Merge lp:~inkscape.dev/inkscape/092+lineheight-fix into lp:inkscape/0.92.x

Proposed by Mc
Status: Merged
Merged at revision: 15338
Proposed branch: lp:~inkscape.dev/inkscape/092+lineheight-fix
Merge into: lp:inkscape/0.92.x
Diff against target: 307 lines (+198/-5)
7 files modified
src/CMakeLists.txt (+1/-0)
src/Makefile_insert (+1/-1)
src/document.cpp (+5/-2)
src/document.h (+9/-0)
src/file-update.cpp (+174/-0)
src/file.h (+1/-1)
src/main.cpp (+7/-1)
To merge this branch: bzr merge lp:~inkscape.dev/inkscape/092+lineheight-fix
Reviewer Review Type Date Requested Status
Martin Owens (community) code Approve
Tavmjong Bah code, behavior, correctness, css Pending
Review via email: mp+315315@code.launchpad.net

Description of the change

This is a branch to work on the conversion of old (pre-0.92) files.
Merge request is primarily to see and review the changes.
Please do not merge before I add a commandline flag to prevent the file update

To post a comment you must log in.
15327. By Mc

updates display

15328. By Mc

clang-format

Revision history for this message
Martin Owens (doctormo) wrote :

Should the name of sp_file_fix_run_recursive be something specific to text/flowtext since that's what it works on? Maybe sp_file_text_run_recursive would work.

Should the comment in src/file.cpp:214 be kept without a comment?

Everything else looks great.

Revision history for this message
Martin Owens (doctormo) wrote :

I get the error:

document.o: In function `SPDocument::createDoc(Inkscape::XML::Document*, char const*, char const*, char const*, unsigned int, SPDocument*)':
/home/doctormo/Projects/inkscape/92/build/src/../../src/document.cpp:457: undefined reference to `sp_file_fix_text(SPDocument*)'

When trying to compile. Must be a build error, is make not enough or does it need a reconfigure?

15329. By Mc

add file in automake

Revision history for this message
Mc (mc...) wrote :

It's because you're using autotools build. It might need a reconfigure after checking this commit, I added a file.

15330. By Mc

useless change

15331. By Mc

merge .92.x

Revision history for this message
Martin Owens (doctormo) wrote :

Merged, compiled and tested as working against pepper and carrot.

review: Approve (code)
15332. By Mc

Actually write changes to the file (!)

15333. By Mc

merge .92.x

15334. By Mc

fix for blank lines at beginning of text

15335. By Mc

add option --do-not-fix-pre-92 to prevent the automatic fix

15336. By Mc

merge .92.x

15337. By Mc

minor fix

15338. By Mc

rename helper function

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

On Sun, 2017-01-22 at 16:51 +0000, Mc wrote:
> Mc has proposed merging lp:~inkscape.dev/inkscape/092+lineheight-fix
> into lp:inkscape/0.92.x.
>
> Requested reviews:
>   Tavmjong Bah (tavmjong-free): code, behavior, correctness, css
>
> For more details, see:
> https://code.launchpad.net/~inkscape.dev/inkscape/092+lineheight-fix/
> +merge/315315
>
> This is a branch to work on the conversion of old (pre-0.92) files.
> Merge request is primarily to see and review the changes.
> Please do not merge before I add a commandline flag to prevent the
> file update

Nicely structured!

1. Documentation!

2. Code style:

    if {
      // Brackets even if one line.
    }

    for {
      // Brackets even if one line.
    }

3. gchar

   Do you really need to use gchar instead of std::string?

4. fix_blank_line:

   Hopefully won't be necessary with proper fix.

   Why are you saving font-size from non-empty lines?

   <text style="font-size:20px">
     <tspan sodipodi:role="line" style="font-size:10px">xxx</tspan>
     <tspan sodipodi:role="line">yyy<tspan>

   'yyy' should be 20px high.

5. fix_line_spacing:

   This is rather brute force but maybe that is OK.

   A value of 0.00% is the same as 0.

   Why is it necessary to set line_height to 0.01% for flowed text?

6. fix_font_size:

   Also rather brute force.

   Why is this recursive? A tspan with role 'line' should not contain
   another tspan with role 'line'. Ditto for flowPara. (You don't
   call fix_line_spacing recursively, why here?)

   Why are you testing if fontsize is set inside the loop? It must be
   or you would have returned at the beginning of the function.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-11-03 21:51:32 +0000
3+++ src/CMakeLists.txt 2017-01-24 00:26:50 +0000
4@@ -202,6 +202,7 @@
5 event-log.cpp
6 extract-uri.cpp
7 file.cpp
8+ file-update.cpp
9 filter-chemistry.cpp
10 filter-enums.cpp
11 gc-anchored.cpp
12
13=== modified file 'src/Makefile_insert'
14--- src/Makefile_insert 2016-09-27 10:14:53 +0000
15+++ src/Makefile_insert 2017-01-24 00:26:50 +0000
16@@ -40,7 +40,7 @@
17 enums.h \
18 event-log.cpp event-log.h event.h \
19 extract-uri.cpp extract-uri.h \
20- file.cpp file.h \
21+ file.cpp file-update.cpp file.h \
22 fill-or-stroke.h \
23 filter-chemistry.cpp filter-chemistry.h \
24 filter-enums.cpp filter-enums.h \
25
26=== modified file 'src/document.cpp'
27--- src/document.cpp 2016-11-28 22:20:00 +0000
28+++ src/document.cpp 2017-01-24 00:26:50 +0000
29@@ -50,6 +50,7 @@
30 #include "display/drawing-item.h"
31 #include "document-private.h"
32 #include "document-undo.h"
33+#include "file.h"
34 #include "id-clash.h"
35 #include "inkscape.h"
36 #include "inkscape-version.h"
37@@ -78,7 +79,7 @@
38 // since we want it to happen when there are no more updates.
39 #define SP_DOCUMENT_REROUTING_PRIORITY (G_PRIORITY_HIGH_IDLE - 1)
40
41-
42+bool sp_do_not_fix_pre_92 = false;
43 static gint sp_document_idle_handler(gpointer data);
44 static gint sp_document_rerouting_handler(gpointer data);
45
46@@ -452,7 +453,9 @@
47 sigc::ptr_fun(&DocumentUndo::resetKey), document)
48 ));
49 document->oldSignalsConnected = true;
50-
51+ if ( (!sp_do_not_fix_pre_92) && sp_version_inside_range( document->root->version.inkscape, 0, 1, 0, 92 ) ) {
52+ sp_file_fix_text(document);
53+ }
54 return document;
55 }
56
57
58=== modified file 'src/document.h'
59--- src/document.h 2016-06-14 10:26:58 +0000
60+++ src/document.h 2017-01-24 00:26:50 +0000
61@@ -30,6 +30,15 @@
62 #include <set>
63 #include <deque>
64
65+// This variable is introduced with 0.92.1
66+// with the introduction of automatic fix
67+// for files detected to have been created
68+// with previous versions to have a similar
69+// look in 0.92+.
70+extern bool sp_do_not_fix_pre_92;
71+
72+
73+
74 namespace Avoid {
75 class Router;
76 }
77
78=== added file 'src/file-update.cpp'
79--- src/file-update.cpp 1970-01-01 00:00:00 +0000
80+++ src/file-update.cpp 2017-01-24 00:26:50 +0000
81@@ -0,0 +1,174 @@
82+/**
83+ * @file-update
84+ * Operations to bump files from the pre-0.92 era into the 0.92+ era
85+ * (90dpi vs 96dpi, line height problems, and related bugs)
86+ */
87+/* Authors:
88+ * Tavmjong Bah
89+ * Marc Jeanmougin
90+ * su_v
91+ */
92+#include "file.h"
93+#include "sp-root.h"
94+#include "sp-text.h"
95+#include "sp-tspan.h"
96+#include "sp-flowdiv.h"
97+#include "sp-flowtext.h"
98+#include "sp-object.h"
99+#include "sp-item.h"
100+#include "style.h"
101+#include "document.h"
102+#include <string>
103+#include "text-editing.h"
104+
105+using namespace std;
106+
107+bool is_line(SPObject *i)
108+{
109+ if (!(i->getAttribute("sodipodi:role")))
110+ return false;
111+ return !strcmp(i->getAttribute("sodipodi:role"), "line");
112+}
113+
114+
115+void fix_blank_line(SPObject *o)
116+{
117+ if (SP_IS_TEXT(o))
118+ ((SPText *)o)->rebuildLayout();
119+ else if (SP_IS_FLOWTEXT(o))
120+ ((SPFlowtext *)o)->rebuildLayout();
121+
122+ SPIFontSize fontsize = o->style->font_size;
123+ SPILengthOrNormal lineheight = o->style->line_height;
124+ vector<SPObject *> cl = o->childList(false);
125+ Inkscape::Text::Layout::iterator pos = te_get_layout((SPItem *)(o))->begin();
126+ bool beginning = true;
127+ for (vector<SPObject *>::const_iterator ci = cl.begin(); ci != cl.end(); ++ci) {
128+ SPObject *i = *ci;
129+ if ((SP_IS_TSPAN(i) && is_line(i)) || SP_IS_FLOWPARA(i)) {
130+ if (sp_text_get_length((SPItem *)i) <= 1) { // empty line
131+ // Inkscape::Text::Layout::iterator pos = te_get_layout((SPItem*)(o))->charIndexToIterator(1 +
132+ // sp_text_get_length_upto(o,i));
133+ sp_te_insert((SPItem *)o, pos, "\u00a0"); //"\u00a0"
134+ gchar *l = g_strdup_printf("%f", lineheight.value);
135+ gchar *f = g_strdup_printf("%f", fontsize.value);
136+ i->style->line_height.readIfUnset(l);
137+ if (!beginning)
138+ i->style->font_size.read(f);
139+ else
140+ i->style->font_size.readIfUnset(f);
141+ g_free(l);
142+ g_free(f);
143+ } else {
144+ beginning = false;
145+ fontsize = i->style->font_size;
146+ lineheight = o->style->line_height;
147+ }
148+ pos.nextLineCursor();
149+ // pos.cursorDownWithControl();
150+ }
151+ }
152+}
153+
154+void fix_line_spacing(SPObject *o)
155+{
156+ SPILengthOrNormal lineheight = o->style->line_height;
157+ bool inner = false;
158+ vector<SPObject *> cl = o->childList(false);
159+ for (vector<SPObject *>::const_iterator ci = cl.begin(); ci != cl.end(); ++ci) {
160+ SPObject *i = *ci;
161+ if ((SP_IS_TSPAN(i) && is_line(i)) || SP_IS_FLOWPARA(i)) {
162+ // if no line-height attribute, set it
163+ gchar *l = g_strdup_printf("%f", lineheight.value);
164+ i->style->line_height.readIfUnset(l);
165+ g_free(l);
166+ }
167+ inner = true;
168+ }
169+ if (inner) {
170+ if (SP_IS_TEXT(o)) {
171+ o->style->line_height.read("0.00%");
172+ } else {
173+ o->style->line_height.readIfUnset("0.01%");
174+ }
175+ }
176+}
177+
178+void fix_font_name(SPObject *o)
179+{
180+ vector<SPObject *> cl = o->childList(false);
181+ for (vector<SPObject *>::const_iterator ci = cl.begin(); ci != cl.end(); ++ci)
182+ fix_font_name(*ci);
183+ string prev = o->style->font_family.value ? o->style->font_family.value : o->style->font_family.value_default;
184+ if (prev == "Sans")
185+ o->style->font_family.read("sans-serif");
186+ else if (prev == "Serif")
187+ o->style->font_family.read("serif");
188+ else if (prev == "Monospace")
189+ o->style->font_family.read("monospace");
190+}
191+
192+
193+void fix_font_size(SPObject *o)
194+{
195+ SPIFontSize fontsize = o->style->font_size;
196+ if (!fontsize.set)
197+ return;
198+ bool inner = false;
199+ vector<SPObject *> cl = o->childList(false);
200+ for (vector<SPObject *>::const_iterator ci = cl.begin(); ci != cl.end(); ++ci) {
201+ SPObject *i = *ci;
202+ fix_font_size(i);
203+ if ((SP_IS_TSPAN(i) && is_line(i)) || SP_IS_FLOWPARA(i)) {
204+ inner = true;
205+ gchar *s = g_strdup_printf("%f", fontsize.value);
206+ if (fontsize.set)
207+ i->style->font_size.readIfUnset(s);
208+ g_free(s);
209+ }
210+ }
211+ if (inner && (SP_IS_TEXT(o) || SP_IS_FLOWTEXT(o)))
212+ o->style->font_size.clear();
213+}
214+
215+
216+
217+// helper function
218+void sp_file_text_run_recursive(void (*f)(SPObject *), SPObject *o)
219+{
220+ if (SP_IS_TEXT(o) || SP_IS_FLOWTEXT(o))
221+ f(o);
222+ else {
223+ vector<SPObject *> cl = o->childList(false);
224+ for (vector<SPObject *>::const_iterator ci = cl.begin(); ci != cl.end(); ++ci)
225+ sp_file_text_run_recursive(f, *ci);
226+ }
227+}
228+
229+// does not work :(
230+void fix_update(SPObject *o) {
231+ o->style->write();
232+ o->updateRepr();
233+}
234+
235+void sp_file_fix_text(SPDocument *doc)
236+{
237+ sp_file_text_run_recursive(fix_blank_line, doc->getRoot());
238+ sp_file_text_run_recursive(fix_line_spacing, doc->getRoot());
239+ sp_file_text_run_recursive(fix_font_name, doc->getRoot());
240+ sp_file_text_run_recursive(fix_font_size, doc->getRoot());
241+ sp_file_text_run_recursive(fix_update, doc->getRoot());
242+}
243+
244+
245+
246+/*
247+ Local Variables:
248+ mode:c++
249+ c-file-style:"stroustrup"
250+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
251+ indent-tabs-mode:nil
252+ fill-column:99
253+ End:
254+*/
255+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
256
257=== modified file 'src/file.h'
258--- src/file.h 2014-10-08 02:22:03 +0000
259+++ src/file.h 2017-01-24 00:26:50 +0000
260@@ -203,7 +203,7 @@
261 * clean unused defs out of file
262 */
263 void sp_file_vacuum (SPDocument *doc);
264-
265+void sp_file_fix_text(SPDocument *doc);
266
267 #endif // SEEN_SP_FILE_H
268
269
270=== modified file 'src/main.cpp'
271--- src/main.cpp 2017-01-18 20:32:49 +0000
272+++ src/main.cpp 2017-01-24 00:26:50 +0000
273@@ -177,6 +177,7 @@
274 SP_ARG_SHELL,
275 SP_ARG_VERSION,
276 SP_ARG_VACUUM_DEFS,
277+ SP_ARG_DO_NOT_FIX_PRE_92,
278 #ifdef WITH_DBUS
279 SP_ARG_DBUS_LISTEN,
280 SP_ARG_DBUS_NAME,
281@@ -241,7 +242,6 @@
282 static gchar *sp_export_svg_utf8 = NULL;
283 static gchar *sp_global_printer_utf8 = NULL;
284
285-
286 /**
287 * Reset variables to default values.
288 */
289@@ -280,6 +280,7 @@
290 sp_query_all = FALSE;
291 sp_query_id = NULL;
292 sp_vacuum_defs = FALSE;
293+ sp_do_not_fix_pre_92 = FALSE;
294 #ifdef WITH_DBUS
295 sp_dbus_listen = FALSE;
296 sp_dbus_name = NULL;
297@@ -526,6 +527,11 @@
298 N_("Start Inkscape in interactive shell mode."),
299 NULL},
300
301+ {"do-not-fix-pre-92", 0,
302+ POPT_ARG_NONE, &sp_do_not_fix_pre_92, SP_ARG_DO_NOT_FIX_PRE_92,
303+ N_("Prevents automatic fix of pre-92 files on opening them."),
304+ NULL},
305+
306 POPT_AUTOHELP POPT_TABLEEND
307 };
308

Subscribers

People subscribed via source and target branches