summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-12-07 20:47:44 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-12-07 20:47:44 +0000
commit075a88fc7edbec8682bcd672de325ec1bedf129f (patch)
tree33d64f8ddc366a96e2c480b672224d44fc0e6355 /src/extension
parentUpdate to trunk (diff)
parentFix bug 1733422 - Bezier and pencil tool don't work form: from clipboard (diff)
downloadinkscape-075a88fc7edbec8682bcd672de325ec1bedf129f.tar.gz
inkscape-075a88fc7edbec8682bcd672de325ec1bedf129f.zip
Mege trunk into powerpencilII
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/internal/latex-text-renderer.cpp101
1 files changed, 63 insertions, 38 deletions
diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp
index d1cf7e484..7a1cacbf2 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -260,6 +260,11 @@ void LaTeXTextRenderer::sp_use_render(SPUse *use)
void LaTeXTextRenderer::sp_text_render(SPText *textobj)
{
+ // Nothing to do here... (so don't emit an empty box)
+ // Also avoids falling out of sync with the CairoRenderer (which won't render anything in this case either)
+ if (textobj->layout.getActualLength() == 0)
+ return;
+
// Only PDFLaTeX supports importing a single page of a graphics file,
// so only PDF backend gets interleaved text/graphics
if (_pdflatex && _omittext_state == GRAPHIC_ON_TOP)
@@ -271,16 +276,20 @@ void LaTeXTextRenderer::sp_text_render(SPText *textobj)
// Align vertically on the baseline of the font (retreived from the anchor point)
// Align horizontally on anchorpoint
gchar const *alignment = NULL;
+ gchar const *alignstack = NULL;
switch (style->text_anchor.computed) {
case SP_CSS_TEXT_ANCHOR_START:
- alignment = "[lb]";
+ alignment = "[lt]";
+ alignstack = "[l]";
break;
case SP_CSS_TEXT_ANCHOR_END:
- alignment = "[rb]";
+ alignment = "[rt]";
+ alignstack = "[r]";
break;
case SP_CSS_TEXT_ANCHOR_MIDDLE:
default:
- alignment = "[b]";
+ alignment = "[t]";
+ alignstack = "[c]";
break;
}
Geom::Point anchor = textobj->attributes.firstXY() * transform();
@@ -327,39 +336,16 @@ void LaTeXTextRenderer::sp_text_render(SPText *textobj)
os << "\\rotatebox{" << degrees << "}{";
}
os << "\\makebox(0,0)" << alignment << "{";
- os << "\\smash{"; // smash the text, to be able to put the makebox coordinates at the baseline
+ os << "\\shortstack" << alignstack << "{";
+ os << "\\smash{";
+ bool smash_closed = false;
// Walk through all spans in the text object.
// Write span strings to LaTeX, associated with font weight and style.
Inkscape::Text::Layout const &layout = *(te_get_layout (textobj));
- for (Inkscape::Text::Layout::iterator li = layout.begin(), le = layout.end();
+ for (Inkscape::Text::Layout::iterator li = layout.begin(), le = layout.end();
li != le; li.nextStartOfSpan())
{
- SPStyle const &spanstyle = *(sp_te_style_at_position (textobj, li));
- bool is_bold = false, is_italic = false, is_oblique = false;
-
- if (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_600 ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_700 ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_800 ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_900 ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLD ||
- spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLDER)
- {
- is_bold = true;
- os << "\\textbf{";
- }
- if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_ITALIC)
- {
- is_italic = true;
- os << "\\textit{";
- }
- if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_OBLIQUE)
- {
- is_oblique = true;
- os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so...
- }
-
Inkscape::Text::Layout::iterator ln = li;
ln.nextStartOfSpan();
Glib::ustring uspanstr = sp_te_get_string_multiline (textobj, li, ln);
@@ -367,22 +353,61 @@ void LaTeXTextRenderer::sp_text_render(SPText *textobj)
if (!spanstr) {
continue;
}
+
+ bool is_bold = false, is_italic = false, is_oblique = false;
+
+ // newline character only -> don't attempt to add style (will break compilation in LaTeX)
+ if (g_strcmp0(spanstr, "\n")) {
+ SPStyle const &spanstyle = *(sp_te_style_at_position (textobj, li));
+ if (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_600 ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_700 ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_800 ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_900 ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLD ||
+ spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLDER)
+ {
+ is_bold = true;
+ os << "\\textbf{";
+ }
+ if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_ITALIC)
+ {
+ is_italic = true;
+ os << "\\textit{";
+ }
+ if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_OBLIQUE)
+ {
+ is_oblique = true;
+ os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so...
+ }
+ }
+
// replace carriage return with double slash
- gchar ** splitstr = g_strsplit(spanstr, "\n", -1);
- gchar *spanstr_new = g_strjoinv("\\\\ ", splitstr);
- os << spanstr_new;
+ gchar ** splitstr = g_strsplit(spanstr, "\n", 2);
+ os << splitstr[0];
+
+ // smash the first line of the text only, to be able to align the rest of the makebox top
+ // assuming that spans always end at the end of a line
+ if (g_strv_length(splitstr) > 1)
+ {
+ if (!smash_closed)
+ {
+ os << "}"; // smash end
+ smash_closed = true;
+ }
+ os << "\\\\";
+ }
+
g_strfreev(splitstr);
- g_free(spanstr_new);
if (is_oblique) { os << "}"; } // oblique end
if (is_italic) { os << "}"; } // italic end
if (is_bold) { os << "}"; } // bold end
}
- os << "}"; // smash end
- if (has_rotation) {
- os << "}"; // rotatebox end
- }
+ if (!smash_closed) { os << "}"; } // smash end
+ os << "}"; // shortstack end
+ if (has_rotation) { os << "}"; } // rotatebox end
os << "}"; //makebox end
os << "}%\n"; // put end