]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Bugfix on fill-with implementation: it loops when there's only one word.
authorAndrea Zagli <azagli@libero.it>
Tue, 1 Nov 2011 12:48:58 +0000 (13:48 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 1 Nov 2011 12:50:07 +0000 (13:50 +0100)
Because it is always one line.
refs #172

.gitignore
src/rptprint.c
tests/test_report.rpt
tests/test_report_db.rpt
tests/test_report_newline.rpt [new file with mode: 0644]
tests/test_rptprint_mm.rptr [new file with mode: 0644]

index 1fb312c035dee2bfca0b51d44222d33fe83df76e..237bf03360f94078b9902b8d0dcabb98d190cadc 100644 (file)
@@ -53,8 +53,6 @@ tests/test_rptreport
 tests/test_rptreport_creation
 tests/test_rptreport_liststore
 tests/test_report_created*
-tests/test_rptprint_mm.rptr
-tests/test_report_newline.rpt
 POTFILES
 mkinstalldirs
 stamp-it
index cb926e724246a571ee860e0466c276a6cfcaa5e1..e833555ffabdc772dfea35c735e4f6db4343fe98 100644 (file)
@@ -1059,6 +1059,8 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
        if (prop != NULL
            && g_strcmp0 (g_strstrip (prop), "") != 0)
                {
+                       PangoLayoutLine *line;
+                       PangoRectangle rect;
                        gint lines;
 
                        GString *text_tmp;
@@ -1069,12 +1071,17 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
 
                        g_string_append (text_tmp, prop);
                        pango_layout_set_text (playout, text_tmp->str, -1);
-                       while (lines == pango_layout_get_line_count (playout))
+                       line = pango_layout_get_line (playout, pango_layout_get_line_count (playout) - 1);
+                       pango_layout_line_get_pixel_extents (line, NULL, &rect);
+                       while (lines == pango_layout_get_line_count (playout)
+                              && rect.width < layout_width)
                                {
                                        g_string_append (text, prop);
 
                                        g_string_append (text_tmp, prop);
                                        pango_layout_set_text (playout, text_tmp->str, -1);
+                                       line = pango_layout_get_line (playout, pango_layout_get_line_count (playout) - 1);
+                                       pango_layout_line_get_pixel_extents (line, NULL, &rect);
                                }
 
                        g_string_free (text_tmp, TRUE);
index 74588112431493576329dc02c0e1c169591074d2..10c269da3df78ce7969522a442242c1f1c1b017a 100644 (file)
   <page width="297,000000" height="210,000000" margin-top="10,000000" margin-right="10,000000" margin-bottom="10,000000" margin-left="10,000000"/>
   <report>
     <page-header first-page="y" last-page="y" height="27,000000">
-      <text name="title" x="0,000000" y="0,000000" width="277,000000" height="10,000000" font-name="Droid Sans" font-size="11,000000" font-bold="y" font-color="#000000FF" source="&quot;Report's Title&quot;"/>
-      <text name="title_0" x="0,000000" y="15,000000" width="50,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Book's title&quot;"/>
-      <text name="title_1" x="55,000000" y="15,000000" width="76,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Author&quot;"/>
-      <line name="line1" x="0,000000" y="25,000000" width="277,000000" height="0,000000"/>
+      <text name="title" x="0,000000" y="0,000000" width="277,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="11,000000" font-bold="y" font-color="#000000FF" source="&quot;Report's Title&quot;"/>
+      <text name="title_0" x="0,000000" y="15,000000" width="50,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Book's title&quot;"/>
+      <text name="title_1" x="55,000000" y="15,000000" width="76,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="9,000000" font-bold="y" font-color="#000000FF" source="&quot;Author&quot;"/>
+      <line name="line1" x="0,000000" y="25,000000" width="277,000000" height="0,000000" visible="y"/>
     </page-header>
     <body height="15,000000">
-      <text name="field_0" x="0,000000" y="0,000000" width="50,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_0]"/>
-      <text name="field_1" x="55,000000" y="0,000000" width="76,000000" height="10,000000" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_1]"/>
+      <text name="field_0" x="0,000000" y="0,000000" width="50,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_0]"/>
+      <text name="field_1" x="55,000000" y="0,000000" width="76,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="9,000000" font-color="#000000FF" source="[field_1]"/>
     </body>
     <page-footer first-page="y" last-page="y" height="12,000000">
-      <line name="line2" x="0,000000" y="0,000000" width="277,000000" height="0,000000"/>
-      <text name="pages" x="0,000000" y="2,000000" width="277,000000" height="10,000000" font-name="Droid Sans" font-size="8,000000" font-color="#000000FF" horizontal-align="right" source="&quot;Page &quot; &amp; @Page &amp; &quot; of &quot; &amp; @Pages"/>
+      <line name="line2" x="0,000000" y="0,000000" width="277,000000" height="0,000000" visible="y"/>
+      <text name="pages" x="0,000000" y="2,000000" width="277,000000" height="10,000000" visible="y" font-name="Droid Sans" font-size="8,000000" font-color="#000000FF" horizontal-align="right" source="&quot;Page &quot; &amp; @Page &amp; &quot; of &quot; &amp; @Pages"/>
     </page-footer>
   </report>
 </reptool>
index 05d960ba0ad7d888678ef979ca8b5cddaa384fb3..885206637c9ef46eb9be01d45223a3e106007c16 100644 (file)
 
        <report>
                <report-header height="80">
-                       <text name="rephead" x="10" y="10" width="300" height="70" font-name="Verdana" font-size="16" font-bold="y" font-underline="y" font-color="#0000FF" source="&quot;the report's header&quot;" />
+                       <text name="rephead" x="10" y="10" width="300" height="70" visible="y" font-name="Verdana" font-size="16" font-bold="y" font-underline="y" font-color="#0000FF" source="&quot;the report's header&quot;" />
                </report-header>
                <page-header height="80" first-page="y">
-                       <text name="title" x="10" y="10" width="300" height="50" font-name="Courier New" font-size="10" font-bold="y" source="&quot;the page's title&quot; &amp; &quot; - &quot; &amp; @Page" />
-                       <line name="line1" x="10" y="65" width="500" height="0" stroke-width="1.0" />
+                       <text name="title" x="10" y="10" width="300" height="50" visible="y" font-name="Courier New" font-size="10" font-bold="y" source="&quot;the page's title&quot; &amp; &quot; - &quot; &amp; @Page" />
+                       <line name="line1" x="10" y="65" width="500" height="0" visible="y" stroke-width="1.0" />
                </page-header>
                <body height="200">
-                       <text name="txt_id" x="50" y="50" width="100" height="50" border-top-width="1.0" border-top-color="#FF0000" source="[id]" />
-                       <text name="txt_name" x="200" y="50" width="100" height="50" source="[name]" />
-                       <text name="txt_req" x="50" y="100" width="100" height="50" source="[nonexistent]" />
-                       <rect name="rect1" x="400" y="10" width="20" height="20" fill-color="#00FF00" />
-                       <image name="img1" x="450" y="10" width="60" height="60" border-bottom-width="1.0" border-bottom-color="#FF0000" border-bottom-style="10;10" source="tests/gnome-globe.png" />
+                       <text name="txt_id" x="50" y="50" width="100" height="50" visible="y" border-top-width="1.0" border-top-color="#FF0000" source="[id]" fill-with="." />
+                       <text name="txt_name" x="200" y="50" width="100" height="50" visible="y" source="[name]" />
+                       <text name="txt_req" x="50" y="100" width="100" height="50" visible="y" source="[nonexistent]" />
+                       <rect name="rect1" x="400" y="10" width="20" height="20" visible="y" fill-color="#00FF00" />
+                       <image name="img1" x="450" y="10" width="60" height="60" visible="y" border-bottom-width="1.0" border-bottom-color="#FF0000" border-bottom-style="10;10" source="tests/gnome-globe.png" />
                </body>
                <report-footer height="50">
-                       <line name="line3" x="10" y="10" width="500" height="0" stroke-color="#FFFF00" stroke-style="50;10" />
-                       <text name="txt_report_footer" x="10" y="20" width="500" height="30" horizontal-align="center" source="&quot;the report's footer&quot;" />
-                       <line name="line4" x="10" y="50" width="500" height="0" stroke-color="#FFFF00" stroke-style="1;5" />
+                       <line name="line3" x="10" y="10" width="500" height="0" visible="y" stroke-color="#FFFF00" stroke-style="50;10" />
+                       <text name="txt_report_footer" x="10" y="20" width="500" height="30" visible="y" horizontal-align="center" source="&quot;the report's footer&quot;" />
+                       <line name="line4" x="10" y="50" width="500" height="0" visible="y" stroke-color="#FFFF00" stroke-style="1;5" />
                </report-footer>
                <page-footer height="80" first-page="y" last-page="y">
-                       <line name="line2" x="10" y="10" width="500" height="0" />
-                       <text name="footer" x="10" y="20" width="300" height="50" source="&quot;the page's footer&quot;" />
-                       <ellipse name="ellipse1" x="400" y="50" width="20" height="10" stroke-color="#FF0000" fill-color="#00FF00" />
-                       <text name="page_n" x="500" y="20" width="50" height="50" source="@Page &amp; &quot;/&quot; &amp; @Pages" />
+                       <line name="line2" x="10" y="10" width="500" height="0" visible="y" />
+                       <text name="footer" x="10" y="20" width="300" height="50" visible="y" source="&quot;the page's footer&quot;" />
+                       <ellipse name="ellipse1" x="400" y="50" width="20" height="10" visible="y" stroke-color="#FF0000" fill-color="#00FF00" />
+                       <text name="page_n" x="500" y="20" width="50" height="50" visible="y" source="@Page &amp; &quot;/&quot; &amp; @Pages" />
                </page-footer>
        </report>
 </reptool>
diff --git a/tests/test_report_newline.rpt b/tests/test_report_newline.rpt
new file mode 100644 (file)
index 0000000..639bf14
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<reptool>
+  <properties>
+    <name>Newline test</name>
+    <description>A report to test if the newline character (#10) works</description>
+  </properties>
+  <page width="595.000000" height="842.000000" margin-left="100.000000" margin-top="200.000000"/>
+  <report>
+    <body>
+      <text name="txt_id" visible="y" x="50.000000" y="50.000000" width="100.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="&quot;text with&#10;new line&quot;"/>
+      <text name="txt_invisible" visible="y" x="50.000000" y="250.000000" width="100.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="&quot;text with&#10;new line&quot;" letter-spacing="20"/>
+      <text name="txt_long" visible="y" x="50.000000" y="350.000000" width="300.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" border-right-width="1" border-right-color="#000" font-name="Sans" font-size="12.000000" source="&quot;text with new line&quot;" fill-with="."/>
+      <text name="txt_dot" visible="y" x="50.000000" y="400.000000" width="300.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="&quot;.&quot;"/>
+      <text name="txt_long_with_spacing" visible="y" x="0.000000" y="450.000000" width="400.000000" height="50.000000" border-top-width="1.000000" border-top-color="#FF0000FF" font-name="Sans" font-size="12.000000" source="&quot;text with&#10;new line&quot;" letter-spacing="10"/>
+      <text name="txt_date" visible="y" x="0.000000" y="500.000000" width="400.000000" height="50.000000" font-name="Sans" font-size="12.000000" source="@Date{%d/%m/%Y} &amp; &quot; &quot; &amp; @Time{%H.%M.%S}" letter-spacing="10"/>
+    </body>
+  </report>
+</reptool>
diff --git a/tests/test_rptprint_mm.rptr b/tests/test_rptprint_mm.rptr
new file mode 100644 (file)
index 0000000..cdf540d
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" ?>
+<reptool_report>
+       <properties>
+               <unit-length>mm</unit-length>
+       </properties>
+       <page width="210" height="297">
+               <text x="10" y="20" width="210" height="100" visible="y" border-top-width="2.83" border-bottom-width="2.83" font-size="12" font-color="#0F0" border-top="2.83" border-bottom="2.83">Text sample</text>
+               <!--<line x="10" y="300" width="100" height="0" visible="y" stroke-color="#F00" />
+               <image x="250" y="180" width="300" height="200" visible="y" border-top-width="1.0" border-right-width="1.0" border-bottom-width="1.0" border-left-width="1.0" source="tests/city.png" />
+               <rect x="10" y="500" width="400" height="10" visible="y" fill-color="#00F" />
+               <text x="10" y="400" width="100" height="50" visible="y" border-top-width="1.0" border-right-width="1.0" border-bottom-width="1.0" border-left-width="1.0" border-top-color="#FF0000" border-right-color="#FF0000" border-bottom-color="#FF0000" border-left-color="#FF0000" background-color="#000000" font-color="#FFFFFF">White on black</text>
+       </page>
+
+       <page width="595" height="842">
+               <text x="10" y="300" width="300" height="800" visible="y" font-size="30" font-color="#FF0">Text sample on second page</text>
+               <line x="10" y="300" width="100" height="0" visible="y" stroke-color="#0F0" />
+               <ellipse x="200" y="700" width="100" height="30" visible="y" stroke-color="#FF0000" fill-color="#0000FF" />
+               <text x="350" y="20" width="200" height="100" visible="y" font-underline="single">Underline single</text>
+               <text x="350" y="120" width="200" height="100" visible="y" font-underline="double">Underline double</text>
+               <text x="350" y="220" width="200" height="100" visible="y" font-underline="low">Underline low</text>
+               <text x="350" y="320" width="200" height="100" visible="y" font-underline="error">Underline error</text>
+               <text x="350" y="420" width="200" height="100" visible="y" font-bold="y" font-color="#FF0000" font-strike="y">Text striked and bold</text>
+               <text x="350" y="520" width="200" height="100" visible="y" font-italic="y">Text italic</text>-->
+       </page>
+</reptool_report>