Line Height for Text Table

If you have any questions regarding Quartam PDF Library for LiveCode, this is the place to get answers from your fellow users - experts and newbies alike.
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
revnor
Posts:3
Joined:Wed Feb 15, 2012 7:04 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Line Height for Text Table

Post by revnor » Wed Feb 15, 2012 7:09 pm

I'm trying to use qrtPDF_WriteTextTable but don't see any way to adjust the line height so that the characters won't run together vertically. Is there a command I've missed? Thanks.

.. Ron

JanSchenkel
Site Admin
Posts:110
Joined:Sun Jul 18, 2010 5:21 pm
Location:Aalst, Belgium
Contact:

Re: Line Height for Text Table

Post by JanSchenkel » Fri Feb 17, 2012 4:03 pm

Hi Ron,

Can you give me an example script that shows the problem?
If my memory serves me well, it should automagically adapt to the current font height.

TIA,

Jan Schenkel.
Quartam Developer Tools for LiveCode
http://www.quartam.com

revnor
Posts:3
Joined:Wed Feb 15, 2012 7:04 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Line Height for Text Table

Post by revnor » Mon Mar 19, 2012 4:08 pm

Hi Jan. Apologies for being soooo late replying but I had given up on the table idea, created the report in a different manner and then forgot that I had asked the question. BUT I would still like to know where I'm going wrong. I did a small test which includes the basics of my procedure. The result I get is:
PDFTableTest.png
Graphic showing my result
(46.22KiB)Not downloaded yet
And the whole test file (only 5K unzipped) is:
PDFTableTest.zip
Test code
(2KiB)Downloaded 1416 times
So what totally stupid thing am I doing or not doing? Thanks.

... Ron

JanSchenkel
Site Admin
Posts:110
Joined:Sun Jul 18, 2010 5:21 pm
Location:Aalst, Belgium
Contact:

Re: Line Height for Text Table

Post by JanSchenkel » Sun Apr 01, 2012 6:49 pm

Hi Ron,

I too must apologize for the late reply. The past few weeks left me too drained to do much after regular working hours. But today I finally found the time to look into this again. As it turns out, you weren't doing anything wrong, and it is a bug in the library, since the very first release.

The line height was, in fact, a magic number of 5, which worked fine in my examples and tests, but didn't take into account the font size (what was I thinking?). To add insult to injury, this magic number ignored the 'unit' of the document so it was even further off if you didn't use the default unit of millimeters but points instead.

For a temporary patch, replace the current implementation of the 'qrtPDF_WriteTextTable' command with the following:

Code: Select all

command qrtPDF_WriteTextTable pDocID, pText, pColumnWidths, pColumnAligns, pBorder, pFill
   p_qrtPDF_AssertDocID pDocID
   p_qrtPDF_AssertIntegerList "columnWidths", pColumnWidths, 0
   p_qrtPDF_AssertTextArray pText
   if pColumnAligns is empty then 
      put sDocumentsA[pDocID][kp_TextAlign] into pColumnAligns
   end if
   p_qrtPDF_AssertAlignList pColumnAligns
   -- backward compatibility: border parameter is new in version 1.1.1
   if pFill is empty and pBorder is a boolean then
      put pBorder into pFill
      put empty into pBorder
   end if
   if pBorder is empty then put "grid" into pBorder
   p_qrtPDF_AssertTableBorder pBorder
   if pFill is empty then put false into pFill
   p_qrtPDF_AssertFlag "fill", pFill
   -- proceed now that we're sure all is right
   local tExtents, tNumberOfRows, tNumberOfColumns
   put the extents of pText into tExtents
   put item 2 of line 1 of tExtents into tNumberOfRows
   put item 2 of line 2 of tExtents into tNumberOfColumns
   local tRow, tColumn, tColumnWidth, tColumnAlign, tX, tY
   local tSingleLineHeight
   put sDocumentsA[pDocId][kp_FontSize] * 6 / 5 into tSingleLineHeight
   repeat with tRow = 1 to tNumberOfRows
      -- calculate the height of the row
      local tRowLines, tHeight
      put 0 into tRowLines
      repeat with tColumn = 1 to tNumberOfColumns
         put item tColumn of pColumnWidths into tColumnWidth
         if tColumnWidth is empty then 
            put item -1 of pColumnWidths into tColumnWidth
         end if
         put max(tRowLines, p_qrtPDF_NumberOfLines(pDocID,tColumnWidth,pText[tRow,tColumn])) into tRowLines
      end repeat
      put tRowLines * tSingleLineHeight into tHeight
      -- page break if needed
      p_qrtPDF_CheckPageBreak pDocID, tHeight
      -- draw the cells in the row
      repeat with tColumn = 1 to tNumberOfColumns
         put item tColumn of pColumnWidths into tColumnWidth
         if tColumnWidth is empty then 
            put item -1 of pColumnWidths into tColumnWidth
         end if
         put item tColumn of pColumnAligns into tColumnAlign
         if tColumnAlign is empty then 
            put item -1 of pColumnAligns into tColumnAlign
         end if
         put sDocumentsA[pDocID][kp_CurrentX] into tX
         put sDocumentsA[pDocID][kp_CurrentY] into tY
         -- determine the border
         local tCellBorder
         switch pBorder
            case "none"
               put empty into tCellBorder
               break
            case "frame"
               put empty into tCellBorder
               if tRow is 1 then
                  put "top," after tCellBorder
               end if
               if tRow is tNumberOfRows then 
                  put "bottom," after tCellBorder
               end if
               if tColumn is 1 then
                  put "left," after tCellBorder
               end if
               if tColumn is tNumberOfColumns then
                  put "right," after tCellBorder
               end if
               delete char -1 of tCellBorder
               break
            case "grid"
               put "top,bottom,left,right" into tCellBorder
               break
         end switch
         -- draw the border here, not in the text area
         -- (otherwise it won't match the row height)
         if "top" is among the items of tCellBorder then
            qrtPDF_DrawLine pDocId, tX, tY, tX + tColumnWidth, tY
         end if
         if "bottom" is among the items of tCellBorder then
            qrtPDF_DrawLine pDocId, tX, tY + tHeight, tX + tColumnWidth, tY + tHeight
         end if
         if "left" is among the items of tCellBorder then
            qrtPDF_DrawLine pDocId, tX, tY, tX, tY + tHeight
         end if
         if "right" is among the items of tCellBorder then
            qrtPDF_DrawLine pDocId, tX + tColumnWidth, tY, tX + tColumnWidth, tY + tHeight
         end if
         -- draw the text area without a border
         qrtPDF_WriteTextArea pDocID, tColumnWidth, tSingleLineHeight, pText[tRow,tColumn], empty, tColumnAlign
         -- move to the right of this cell
         qrtPDF_SetXY pDocID, tX + tColumnWidth, tY
      end repeat
      -- go to the next line
      qrtPDF_DoLineBreak pDocID, tHeight
   end repeat
end qrtPDF_WriteTextTable
I'm going to have to do some more testing before I put this in the next release, but the above patch should get you going again.

Best regards,

Jan Schenkel.
Quartam Developer Tools for LiveCode
http://www.quartam.com

revnor
Posts:3
Joined:Wed Feb 15, 2012 7:04 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Line Height for Text Table

Post by revnor » Sun Apr 08, 2012 3:15 pm

Good sleuthing, Jan. That seems to have done the trick and my test tables are now printing as expected. Thanks.
... Ron

JanSchenkel
Site Admin
Posts:110
Joined:Sun Jul 18, 2010 5:21 pm
Location:Aalst, Belgium
Contact:

Re: Line Height for Text Table

Post by JanSchenkel » Thu Oct 18, 2012 4:42 pm

Due to an overloaded schedule, it took me a while to incorporate this patch into the library. But Quartam PDF Library 1.1.4 is now available and includes this fix, as well as support for 'leftJustify', 'centerJustify' and 'rightJustify' text alignments.

Cheers,

Jan Schenkel.
Quartam Developer Tools for LiveCode
http://www.quartam.com

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable