This diff has been collapsed as it changes many lines, (582 lines changed) Show them Hide them | |||||
@@ -99,6 +99,8 class TCPDF | |||||
99 |
|
99 | |||
100 | attr_accessor :default_table_columns |
|
100 | attr_accessor :default_table_columns | |
101 |
|
101 | |||
|
102 | attr_accessor :max_table_columns | |||
|
103 | ||||
102 | attr_accessor :default_font |
|
104 | attr_accessor :default_font | |
103 |
|
105 | |||
104 | attr_accessor :draw_color |
|
106 | attr_accessor :draw_color | |
@@ -141,11 +143,11 class TCPDF | |||||
141 |
|
143 | |||
142 | attr_accessor :links |
|
144 | attr_accessor :links | |
143 |
|
145 | |||
144 | attr_accessor :listordered |
|
146 | attr_accessor :list_ordered | |
145 |
|
147 | |||
146 | attr_accessor :listcount |
|
148 | attr_accessor :list_count | |
147 |
|
149 | |||
148 | attr_accessor :lispacer |
|
150 | attr_accessor :li_spacer | |
149 |
|
151 | |||
150 | attr_accessor :n |
|
152 | attr_accessor :n | |
151 |
|
153 | |||
@@ -226,6 +228,12 class TCPDF | |||||
226 | @diffs ||= [] |
|
228 | @diffs ||= [] | |
227 | @color_flag ||= false |
|
229 | @color_flag ||= false | |
228 | @default_table_columns ||= 4 |
|
230 | @default_table_columns ||= 4 | |
|
231 | @table_columns ||= 0 | |||
|
232 | @max_table_columns ||= [] | |||
|
233 | @tr_id ||= 0 | |||
|
234 | @max_td_page ||= [] | |||
|
235 | @max_td_y ||= [] | |||
|
236 | @t_columns ||= 0 | |||
229 | @default_font ||= "FreeSans" if unicode |
|
237 | @default_font ||= "FreeSans" if unicode | |
230 | @default_font ||= "Helvetica" |
|
238 | @default_font ||= "Helvetica" | |
231 | @draw_color ||= '0 G' |
|
239 | @draw_color ||= '0 G' | |
@@ -248,9 +256,15 class TCPDF | |||||
248 | @is_unicode = unicode |
|
256 | @is_unicode = unicode | |
249 | @lasth ||= 0 |
|
257 | @lasth ||= 0 | |
250 | @links ||= [] |
|
258 | @links ||= [] | |
251 |
@listordered ||= |
|
259 | @list_ordered ||= [] | |
252 |
@listcount ||= |
|
260 | @list_count ||= [] | |
253 | @lispacer ||= "" |
|
261 | @li_spacer ||= "" | |
|
262 | @li_count ||= 0 | |||
|
263 | @spacer ||= "" | |||
|
264 | @quote_count ||= 0 | |||
|
265 | @prevquote_count ||= 0 | |||
|
266 | @quote_top ||= [] | |||
|
267 | @quote_page ||= [] | |||
254 | @n ||= 2 |
|
268 | @n ||= 2 | |
255 | @offsets ||= [] |
|
269 | @offsets ||= [] | |
256 | @orientation_changes ||= [] |
|
270 | @orientation_changes ||= [] | |
@@ -272,6 +286,7 class TCPDF | |||||
272 | @tempfontsize ||= 10 |
|
286 | @tempfontsize ||= 10 | |
273 | @text_color ||= '0 g' |
|
287 | @text_color ||= '0 g' | |
274 | @underline ||= false |
|
288 | @underline ||= false | |
|
289 | @deleted ||= false | |||
275 | @ws ||= 0 |
|
290 | @ws ||= 0 | |
276 |
|
291 | |||
277 | #Standard Unicode fonts |
|
292 | #Standard Unicode fonts | |
@@ -737,7 +752,7 class TCPDF | |||||
737 | Open(); |
|
752 | Open(); | |
738 | end |
|
753 | end | |
739 | family=@font_family; |
|
754 | family=@font_family; | |
740 | style=@font_style + (@underline ? 'U' : ''); |
|
755 | style=@font_style + (@underline ? 'U' : '') + (@deleted ? 'D' : ''); | |
741 | size=@font_size_pt; |
|
756 | size=@font_size_pt; | |
742 | lw=@line_width; |
|
757 | lw=@line_width; | |
743 | dc=@draw_color; |
|
758 | dc=@draw_color; | |
@@ -1312,6 +1327,7 class TCPDF | |||||
1312 |
|
1327 | |||
1313 | style=style.upcase |
|
1328 | style=style.upcase | |
1314 | style=style.gsub('U',''); |
|
1329 | style=style.gsub('U',''); | |
|
1330 | style=style.gsub('D',''); | |||
1315 | if (style == 'IB') |
|
1331 | if (style == 'IB') | |
1316 | style = 'BI'; |
|
1332 | style = 'BI'; | |
1317 | end |
|
1333 | end | |
@@ -1394,7 +1410,7 class TCPDF | |||||
1394 | # #Removes bold |
|
1410 | # #Removes bold | |
1395 | # :pdf->SetFont(''); |
|
1411 | # :pdf->SetFont(''); | |
1396 | # #Times bold, italic and underlined 14 |
|
1412 | # #Times bold, italic and underlined 14 | |
1397 | # :pdf->SetFont('Times','BIU'); |
|
1413 | # :pdf->SetFont('Times','BIUD'); | |
1398 | # </pre><br /> |
|
1414 | # </pre><br /> | |
1399 | # If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated. |
|
1415 | # If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated. | |
1400 | # @param string :family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained. |
|
1416 | # @param string :family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained. | |
@@ -1426,6 +1442,12 class TCPDF | |||||
1426 | else |
|
1442 | else | |
1427 | @underline=false; |
|
1443 | @underline=false; | |
1428 | end |
|
1444 | end | |
|
1445 | if (style.include?('D')) | |||
|
1446 | @deleted=true; | |||
|
1447 | style= style.gsub('D',''); | |||
|
1448 | else | |||
|
1449 | @deleted=false; | |||
|
1450 | end | |||
1429 | if (style=='IB') |
|
1451 | if (style=='IB') | |
1430 | style='BI'; |
|
1452 | style='BI'; | |
1431 | end |
|
1453 | end | |
@@ -1573,7 +1595,7 class TCPDF | |||||
1573 | #Output a string |
|
1595 | #Output a string | |
1574 | s=sprintf('BT %.2f %.2f Td (%s) Tj ET', x * @k, (@h-y) * @k, escapetext(txt)); |
|
1596 | s=sprintf('BT %.2f %.2f Td (%s) Tj ET', x * @k, (@h-y) * @k, escapetext(txt)); | |
1575 | if (@underline and (txt!='')) |
|
1597 | if (@underline and (txt!='')) | |
1576 |
s += ' ' + do |
|
1598 | s += ' ' + dolinetxt(x, y, txt); | |
1577 | end |
|
1599 | end | |
1578 | if (@color_flag) |
|
1600 | if (@color_flag) | |
1579 | s='q ' + @text_color + ' ' + s + ' Q'; |
|
1601 | s='q ' + @text_color + ' ' + s + ' Q'; | |
@@ -1661,6 +1683,7 class TCPDF | |||||
1661 | k=@k; |
|
1683 | k=@k; | |
1662 | if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak()) |
|
1684 | if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak()) | |
1663 | #Automatic page break |
|
1685 | #Automatic page break | |
|
1686 | if @pages[@page+1].nil? | |||
1664 | x = @x; |
|
1687 | x = @x; | |
1665 | ws = @ws; |
|
1688 | ws = @ws; | |
1666 | if (ws > 0) |
|
1689 | if (ws > 0) | |
@@ -1673,7 +1696,12 class TCPDF | |||||
1673 | @ws = ws; |
|
1696 | @ws = ws; | |
1674 | out(sprintf('%.3f Tw', ws * k)); |
|
1697 | out(sprintf('%.3f Tw', ws * k)); | |
1675 | end |
|
1698 | end | |
|
1699 | else | |||
|
1700 | @page += 1; | |||
|
1701 | @y=@t_margin; | |||
|
1702 | end | |||
1676 | end |
|
1703 | end | |
|
1704 | ||||
1677 | if (w == 0) |
|
1705 | if (w == 0) | |
1678 | w = @w - @r_margin - @x; |
|
1706 | w = @w - @r_margin - @x; | |
1679 | end |
|
1707 | end | |
@@ -1717,7 +1745,10 class TCPDF | |||||
1717 | txt2 = escapetext(txt); |
|
1745 | txt2 = escapetext(txt); | |
1718 | s<<sprintf('BT %.2f %.2f Td (%s) Tj ET', (@x + dx) * k, (@h - (@y + 0.5 * h + 0.3 * @font_size)) * k, txt2); |
|
1746 | s<<sprintf('BT %.2f %.2f Td (%s) Tj ET', (@x + dx) * k, (@h - (@y + 0.5 * h + 0.3 * @font_size)) * k, txt2); | |
1719 | if (@underline) |
|
1747 | if (@underline) | |
1720 |
s<<' ' + do |
|
1748 | s<<' ' + dolinetxt(@x + dx, @y + 0.5 * h + 0.3 * @font_size, txt); | |
|
1749 | end | |||
|
1750 | if (@deleted) | |||
|
1751 | s<<' ' + dolinetxt(@x + dx, @y + 0.3 * h + 0.2 * @font_size, txt); | |||
1721 | end |
|
1752 | end | |
1722 | if (@color_flag) |
|
1753 | if (@color_flag) | |
1723 | s<<' Q'; |
|
1754 | s<<' Q'; | |
@@ -1760,6 +1791,7 class TCPDF | |||||
1760 | # save current position |
|
1791 | # save current position | |
1761 | prevx = @x; |
|
1792 | prevx = @x; | |
1762 | prevy = @y; |
|
1793 | prevy = @y; | |
|
1794 | prevpage = @page; | |||
1763 |
|
1795 | |||
1764 | #Output text with automatic or explicit line breaks |
|
1796 | #Output text with automatic or explicit line breaks | |
1765 |
|
1797 | |||
@@ -1876,6 +1908,7 class TCPDF | |||||
1876 | @x = @l_margin; |
|
1908 | @x = @l_margin; | |
1877 | elsif (ln == 0) |
|
1909 | elsif (ln == 0) | |
1878 | # go to the top-right of the cell |
|
1910 | # go to the top-right of the cell | |
|
1911 | @page = prevpage; | |||
1879 | @y = prevy; |
|
1912 | @y = prevy; | |
1880 | @x = prevx + w; |
|
1913 | @x = prevx + w; | |
1881 | elsif (ln == 2) |
|
1914 | elsif (ln == 2) | |
@@ -2075,6 +2108,29 class TCPDF | |||||
2075 | else |
|
2108 | else | |
2076 | @y += h; |
|
2109 | @y += h; | |
2077 | end |
|
2110 | end | |
|
2111 | ||||
|
2112 | k=@k; | |||
|
2113 | if (@y > @page_break_trigger and !@in_footer and AcceptPageBreak()) | |||
|
2114 | #Automatic page break | |||
|
2115 | if @pages[@page+1].nil? | |||
|
2116 | x = @x; | |||
|
2117 | ws = @ws; | |||
|
2118 | if (ws > 0) | |||
|
2119 | @ws = 0; | |||
|
2120 | out('0 Tw'); | |||
|
2121 | end | |||
|
2122 | AddPage(@cur_orientation); | |||
|
2123 | @x = x; | |||
|
2124 | if (ws > 0) | |||
|
2125 | @ws = ws; | |||
|
2126 | out(sprintf('%.3f Tw', ws * k)); | |||
|
2127 | end | |||
|
2128 | else | |||
|
2129 | @page += 1; | |||
|
2130 | @y=@t_margin; | |||
|
2131 | end | |||
|
2132 | end | |||
|
2133 | ||||
2078 | end |
|
2134 | end | |
2079 | alias_method :ln, :Ln |
|
2135 | alias_method :ln, :Ln | |
2080 |
|
2136 | |||
@@ -2473,6 +2529,7 class TCPDF | |||||
2473 |
|
2529 | |||
2474 | def putType0(font) |
|
2530 | def putType0(font) | |
2475 | #Type0 |
|
2531 | #Type0 | |
|
2532 | newobj(); | |||
2476 | out('<</Type /Font') |
|
2533 | out('<</Type /Font') | |
2477 | out('/Subtype /Type0') |
|
2534 | out('/Subtype /Type0') | |
2478 | out('/BaseFont /'+font['name']+'-'+font['cMap']) |
|
2535 | out('/BaseFont /'+font['name']+'-'+font['cMap']) | |
@@ -2525,7 +2582,7 class TCPDF | |||||
2525 | out('/Width ' + info['w'].to_s); |
|
2582 | out('/Width ' + info['w'].to_s); | |
2526 | out('/Height ' + info['h'].to_s); |
|
2583 | out('/Height ' + info['h'].to_s); | |
2527 | if (info['cs']=='Indexed') |
|
2584 | if (info['cs']=='Indexed') | |
2528 | out('/ColorSpace [/Indexed /DeviceRGB ' + (info['pal'].length/3-1) + ' ' + (@n+1) + ' 0 R]'); |
|
2585 | out('/ColorSpace [/Indexed /DeviceRGB ' + (info['pal'].length/3-1).to_s + ' ' + (@n+1).to_s + ' 0 R]'); | |
2529 | else |
|
2586 | else | |
2530 | out('/ColorSpace /' + info['cs']); |
|
2587 | out('/ColorSpace /' + info['cs']); | |
2531 | if (info['cs']=='DeviceCMYK') |
|
2588 | if (info['cs']=='DeviceCMYK') | |
@@ -2553,7 +2610,7 class TCPDF | |||||
2553 | #Palette |
|
2610 | #Palette | |
2554 | if (info['cs']=='Indexed') |
|
2611 | if (info['cs']=='Indexed') | |
2555 | newobj(); |
|
2612 | newobj(); | |
2556 |
pal=(@compress) ? gzcompress(info['pal']) : |
|
2613 | pal=(@compress) ? gzcompress(info['pal']) : info['pal']; | |
2557 | out('<<' + filter + '/Length ' + pal.length.to_s + '>>'); |
|
2614 | out('<<' + filter + '/Length ' + pal.length.to_s + '>>'); | |
2558 | putstream(pal); |
|
2615 | putstream(pal); | |
2559 | out('endobj'); |
|
2616 | out('endobj'); | |
@@ -2766,10 +2823,10 class TCPDF | |||||
2766 | end |
|
2823 | end | |
2767 |
|
2824 | |||
2768 | # |
|
2825 | # | |
2769 | # Underline text |
|
2826 | # Underline and Deleted text | |
2770 | # @access protected |
|
2827 | # @access protected | |
2771 | # |
|
2828 | # | |
2772 |
def do |
|
2829 | def dolinetxt(x, y, txt) | |
2773 | up = @current_font['up']; |
|
2830 | up = @current_font['up']; | |
2774 | ut = @current_font['ut']; |
|
2831 | ut = @current_font['ut']; | |
2775 | w = GetStringWidth(txt) + @ws * txt.count(' '); |
|
2832 | w = GetStringWidth(txt) + @ws * txt.count(' '); | |
@@ -3350,7 +3407,7 class TCPDF | |||||
3350 |
|
3407 | |||
3351 | # |
|
3408 | # | |
3352 | # Allows to preserve some HTML formatting.<br /> |
|
3409 | # Allows to preserve some HTML formatting.<br /> | |
3353 | # Supports: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small |
|
3410 | # Supports: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, ins, del, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small | |
3354 | # @param string :html text to display |
|
3411 | # @param string :html text to display | |
3355 | # @param boolean :ln if true add a new line after text (default = true) |
|
3412 | # @param boolean :ln if true add a new line after text (default = true) | |
3356 | # @param int :fill Indicates if the background must be painted (1) or transparent (0). Default value: 0. |
|
3413 | # @param int :fill Indicates if the background must be painted (1) or transparent (0). Default value: 0. | |
@@ -3364,12 +3421,38 class TCPDF | |||||
3364 | end |
|
3421 | end | |
3365 |
|
3422 | |||
3366 | @href = nil |
|
3423 | @href = nil | |
3367 |
@style = |
|
3424 | @style = ""; | |
3368 | html.gsub!(/[\t\r\n\f]/, "")#\0\x0B |
|
3425 | @t_cells = [[]]; | |
|
3426 | @table_id = 0; | |||
|
3427 | ||||
|
3428 | # pre calculate | |||
3369 | html.split(/(<[^>]+>)/).each do |element| |
|
3429 | html.split(/(<[^>]+>)/).each do |element| | |
3370 | if "<" == element[0,1] |
|
3430 | if "<" == element[0,1] | |
3371 | #Tag |
|
3431 | #Tag | |
3372 | if (element[1, 1] == '/') |
|
3432 | if (element[1, 1] == '/') | |
|
3433 | closedHTMLTagCalc(element[2..-2].downcase); | |||
|
3434 | else | |||
|
3435 | #Extract attributes | |||
|
3436 | # get tag name | |||
|
3437 | tag = element.scan(/([a-zA-Z0-9]*)/).flatten.delete_if {|x| x.length == 0} | |||
|
3438 | tag = tag[0].downcase; | |||
|
3439 | ||||
|
3440 | # get attributes | |||
|
3441 | attr_array = element.scan(/([^=\s]*)=["\']?([^"\']*)["\']?/) | |||
|
3442 | attrs = {} | |||
|
3443 | attr_array.each do |name, value| | |||
|
3444 | attrs[name.downcase] = value; | |||
|
3445 | end | |||
|
3446 | openHTMLTagCalc(tag, attrs); | |||
|
3447 | end | |||
|
3448 | end | |||
|
3449 | end | |||
|
3450 | @table_id = 0; | |||
|
3451 | ||||
|
3452 | html.split(/(<[A-Za-z!?\/][^>]*?>)/).each do |element| | |||
|
3453 | if "<" == element[0,1] | |||
|
3454 | #Tag | |||
|
3455 | if (element[1, 1] == '/') | |||
3373 | closedHTMLTagHandler(element[2..-2].downcase); |
|
3456 | closedHTMLTagHandler(element[2..-2].downcase); | |
3374 | else |
|
3457 | else | |
3375 | #Extract attributes |
|
3458 | #Extract attributes | |
@@ -3389,14 +3472,32 class TCPDF | |||||
3389 | else |
|
3472 | else | |
3390 | #Text |
|
3473 | #Text | |
3391 | if (@href) |
|
3474 | if (@href) | |
|
3475 | element.gsub!(/[\t\r\n\f]/, ""); | |||
3392 | addHtmlLink(@href, element, fill); |
|
3476 | addHtmlLink(@href, element, fill); | |
3393 | elsif (@tdbegin) |
|
3477 | elsif (@tdbegin) | |
3394 | if ((element.strip.length > 0) and (element != " ")) |
|
3478 | element.gsub!(/[\t\r\n\f]/, ""); | |
3395 | Cell(@tdwidth, @tdheight, unhtmlentities(element.strip), @tableborder, 0, @tdalign, @tdfill); |
|
3479 | element.gsub!(/ /, " "); | |
3396 | elsif (element == " ") |
|
3480 | base_page = @page; | |
3397 | Cell(@tdwidth, @tdheight, '', @tableborder, 0, @tdalign, @tdfill); |
|
3481 | base_x = @x; | |
|
3482 | base_y = @y; | |||
|
3483 | ||||
|
3484 | MultiCell(@tdwidth, @tdheight, unhtmlentities(element.strip), @tableborder, @tdalign, @tdfill, 1); | |||
|
3485 | tr_end = @t_cells[@table_id][@tr_id][@td_id]['j1'] + 1; | |||
|
3486 | if @max_td_page[tr_end].nil? or (@max_td_page[tr_end] < @page) | |||
|
3487 | @max_td_page[tr_end] = @page | |||
|
3488 | @max_td_y[tr_end] = @y | |||
|
3489 | elsif (@max_td_page[tr_end] == @page) | |||
|
3490 | @max_td_y[tr_end] = @y if @max_td_y[tr_end].nil? or (@max_td_y[tr_end] < @y) | |||
|
3491 | end | |||
|
3492 | ||||
|
3493 | @page = base_page; | |||
|
3494 | @x = base_x + @tdwidth; | |||
|
3495 | @y = base_y; | |||
|
3496 | elsif (element.strip.length > 0) | |||
|
3497 | if @pre_state != true | |||
|
3498 | element.gsub!(/[\t\r\n\f]/, ""); | |||
|
3499 | element.gsub!(/ /, " "); | |||
3398 | end |
|
3500 | end | |
3399 | elsif ((element.strip.length > 0) and (element != " ")) |
|
|||
3400 | Write(@lasth, unhtmlentities(element), '', fill); |
|
3501 | Write(@lasth, unhtmlentities(element), '', fill); | |
3401 | end |
|
3502 | end | |
3402 | end |
|
3503 | end | |
@@ -3422,7 +3523,7 class TCPDF | |||||
3422 | # @param int :fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. |
|
3523 | # @param int :fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. | |
3423 | # @see Cell() |
|
3524 | # @see Cell() | |
3424 | # |
|
3525 | # | |
3425 |
def writeHTMLCell(w, h, x, y, html='', border=0, ln= |
|
3526 | def writeHTMLCell(w, h, x, y, html='', border=0, ln=1, fill=0) | |
3426 |
|
3527 | |||
3427 | if (@lasth == 0) |
|
3528 | if (@lasth == 0) | |
3428 | #set row height |
|
3529 | #set row height | |
@@ -3446,6 +3547,24 class TCPDF | |||||
3446 | w = @fw - x - @r_margin; |
|
3547 | w = @fw - x - @r_margin; | |
3447 | end |
|
3548 | end | |
3448 |
|
3549 | |||
|
3550 | b=0; | |||
|
3551 | if (border) | |||
|
3552 | if (border==1) | |||
|
3553 | border='LTRB'; | |||
|
3554 | b='LRT'; | |||
|
3555 | b2='LR'; | |||
|
3556 | elsif border.is_a?(String) | |||
|
3557 | b2=''; | |||
|
3558 | if (border.include?('L')) | |||
|
3559 | b2<<'L'; | |||
|
3560 | end | |||
|
3561 | if (border.include?('R')) | |||
|
3562 | b2<<'R'; | |||
|
3563 | end | |||
|
3564 | b=(border.include?('T')) ? b2 + 'T' : b2; | |||
|
3565 | end | |||
|
3566 | end | |||
|
3567 | ||||
3449 | # store original margin values |
|
3568 | # store original margin values | |
3450 | l_margin = @l_margin; |
|
3569 | l_margin = @l_margin; | |
3451 | r_margin = @r_margin; |
|
3570 | r_margin = @r_margin; | |
@@ -3461,37 +3580,188 class TCPDF | |||||
3461 |
|
3580 | |||
3462 | currentY = GetY(); |
|
3581 | currentY = GetY(); | |
3463 |
|
3582 | |||
|
3583 | @auto_page_break = false; | |||
3464 | # check if a new page has been created |
|
3584 | # check if a new page has been created | |
3465 | if (@page > pagenum) |
|
3585 | if (@page > pagenum) | |
3466 | # design a cell around the text on first page |
|
3586 | # design a cell around the text on first page | |
3467 | currentpage = @page; |
|
3587 | currentpage = @page; | |
3468 | @page = pagenum; |
|
3588 | @page = pagenum; | |
3469 | SetY(GetPageHeight() - restspace - GetBreakMargin()); |
|
3589 | SetY(GetPageHeight() - restspace - GetBreakMargin()); | |
3470 | h = restspace - 1; |
|
3590 | Cell(w, restspace - 1, "", b, 0, 'L', 0); | |
3471 | Cell(w, h, "", border, ln, 'L', 0); |
|
3591 | b = b2; | |
|
3592 | @page += 1; | |||
|
3593 | while @page < currentpage | |||
|
3594 | SetY(@t_margin); # put cursor at the beginning of text | |||
|
3595 | Cell(w, @page_break_trigger - @t_margin, "", b, 0, 'L', 0); | |||
|
3596 | @page += 1; | |||
|
3597 | end | |||
|
3598 | if (border.is_a?(String) and border.include?('B')) | |||
|
3599 | b<<'B'; | |||
|
3600 | end | |||
3472 | # design a cell around the text on last page |
|
3601 | # design a cell around the text on last page | |
3473 | @page = currentpage; |
|
|||
3474 | h = currentY - @t_margin; |
|
|||
3475 | SetY(@t_margin); # put cursor at the beginning of text |
|
3602 | SetY(@t_margin); # put cursor at the beginning of text | |
3476 |
Cell(w, |
|
3603 | Cell(w, currentY - @t_margin, "", b, 0, 'L', 0); | |
3477 | else |
|
3604 | else | |
3478 | h = [h, (currentY - y)].max; |
|
|||
3479 | SetY(y); # put cursor at the beginning of text |
|
3605 | SetY(y); # put cursor at the beginning of text | |
3480 | # design a cell around the text |
|
3606 | # design a cell around the text | |
3481 |
Cell(w, h, "", border, |
|
3607 | Cell(w, [h, (currentY - y)].max, "", border, 0, 'L', 0); | |
3482 | end |
|
3608 | end | |
|
3609 | @auto_page_break = true; | |||
3483 |
|
3610 | |||
3484 | # restore original margin values |
|
3611 | # restore original margin values | |
3485 | SetLeftMargin(l_margin); |
|
3612 | SetLeftMargin(l_margin); | |
3486 | SetRightMargin(r_margin); |
|
3613 | SetRightMargin(r_margin); | |
3487 |
|
3614 | |||
3488 | if (ln) |
|
3615 | @lasth = h | |
3489 | Ln(0); |
|
3616 | ||
|
3617 | # move cursor to specified position | |||
|
3618 | if (ln == 0) | |||
|
3619 | # go to the top-right of the cell | |||
|
3620 | @x = x + w; | |||
|
3621 | @y = y; | |||
|
3622 | elsif (ln == 1) | |||
|
3623 | # go to the beginning of the next line | |||
|
3624 | @x = @l_margin; | |||
|
3625 | @y = currentY; | |||
|
3626 | elsif (ln == 2) | |||
|
3627 | # go to the bottom-left of the cell (below) | |||
|
3628 | @x = x; | |||
|
3629 | @y = currentY; | |||
3490 | end |
|
3630 | end | |
3491 | end |
|
3631 | end | |
3492 | alias_method :write_html_cell, :writeHTMLCell |
|
3632 | alias_method :write_html_cell, :writeHTMLCell | |
3493 |
|
3633 | |||
3494 | # |
|
3634 | # | |
|
3635 | # Check html table tag position. | |||
|
3636 | # | |||
|
3637 | # @param array :table potision array | |||
|
3638 | # @param int :current tr tag id number | |||
|
3639 | # @param int :current td tag id number | |||
|
3640 | # @access private | |||
|
3641 | # @return int : next td_id position. | |||
|
3642 | # value 0 mean that can use position. | |||
|
3643 | # | |||
|
3644 | def checkTableBlockingCellPosition(table, tr_id, td_id ) | |||
|
3645 | 0.upto(tr_id) do |j| | |||
|
3646 | 0.upto(@t_cells[table][j].size - 1) do |i| | |||
|
3647 | if @t_cells[table][j][i]['i0'] <= td_id and td_id <= @t_cells[table][j][i]['i1'] | |||
|
3648 | if @t_cells[table][j][i]['j0'] <= tr_id and tr_id <= @t_cells[table][j][i]['j1'] | |||
|
3649 | return @t_cells[table][j][i]['i1'] - td_id + 1; | |||
|
3650 | end | |||
|
3651 | end | |||
|
3652 | end | |||
|
3653 | end | |||
|
3654 | return 0; | |||
|
3655 | end | |||
|
3656 | ||||
|
3657 | # | |||
|
3658 | # Calculate opening tags. | |||
|
3659 | # | |||
|
3660 | # html table cell array : @t_cells | |||
|
3661 | # | |||
|
3662 | # i0: table cell start position | |||
|
3663 | # i1: table cell end position | |||
|
3664 | # j0: table row start position | |||
|
3665 | # j1: table row end position | |||
|
3666 | # | |||
|
3667 | # +------+ | |||
|
3668 | # |i0,j0 | | |||
|
3669 | # | i1,j1| | |||
|
3670 | # +------+ | |||
|
3671 | # | |||
|
3672 | # example html: | |||
|
3673 | # <table> | |||
|
3674 | # <tr><td></td><td></td><td></td></tr> | |||
|
3675 | # <tr><td colspan=2></td><td></td></tr> | |||
|
3676 | # <tr><td rowspan=2></td><td></td><td></td></tr> | |||
|
3677 | # <tr><td></td><td></td></tr> | |||
|
3678 | # </table> | |||
|
3679 | # | |||
|
3680 | # i: 0 1 2 | |||
|
3681 | # j+----+----+----+ | |||
|
3682 | # :|0,0 |1,0 |2,0 | | |||
|
3683 | # 0| 0,0| 1,0| 2,0| | |||
|
3684 | # +----+----+----+ | |||
|
3685 | # |0,1 |2,1 | | |||
|
3686 | # 1| 1,1| 2,1| | |||
|
3687 | # +----+----+----+ | |||
|
3688 | # |0,2 |1,2 |2,2 | | |||
|
3689 | # 2| | 1,2| 2,2| | |||
|
3690 | # + +----+----+ | |||
|
3691 | # | |1,3 |2,3 | | |||
|
3692 | # 3| 0,3| 1,3| 2,3| | |||
|
3693 | # +----+----+----+ | |||
|
3694 | # | |||
|
3695 | # html table cell array : | |||
|
3696 | # [[[i0=>0,j0=>0,i1=>0,j1=>0],[i0=>1,j0=>0,i1=>1,j1=>0],[i0=>2,j0=>0,i1=>2,j1=>0]], | |||
|
3697 | # [[i0=>0,j0=>1,i1=>1,j1=>1],[i0=>2,j0=>1,i1=>2,j1=>1]], | |||
|
3698 | # [[i0=>0,j0=>2,i1=>0,j1=>3],[i0=>1,j0=>2,i1=>1,j1=>2],[i0=>2,j0=>2,i1=>2,j1=>2]] | |||
|
3699 | # [[i0=>1,j0=>3,i1=>1,j1=>3],[i0=>2,j0=>3,i1=>2,j1=>3]]] | |||
|
3700 | # | |||
|
3701 | # @param string :tag tag name (in upcase) | |||
|
3702 | # @param string :attr tag attribute (in upcase) | |||
|
3703 | # @access private | |||
|
3704 | # | |||
|
3705 | def openHTMLTagCalc(tag, attrs) | |||
|
3706 | #Opening tag | |||
|
3707 | case (tag) | |||
|
3708 | when 'table' | |||
|
3709 | @max_table_columns[@table_id] = 0; | |||
|
3710 | @t_columns = 0; | |||
|
3711 | @tr_id = -1; | |||
|
3712 | when 'tr' | |||
|
3713 | if @max_table_columns[@table_id] < @t_columns | |||
|
3714 | @max_table_columns[@table_id] = @t_columns; | |||
|
3715 | end | |||
|
3716 | @t_columns = 0; | |||
|
3717 | @tr_id += 1; | |||
|
3718 | @td_id = -1; | |||
|
3719 | @t_cells[@table_id].push [] | |||
|
3720 | when 'td', 'th' | |||
|
3721 | @td_id += 1; | |||
|
3722 | if attrs['colspan'].nil? or attrs['colspan'] == '' | |||
|
3723 | colspan = 1; | |||
|
3724 | else | |||
|
3725 | colspan = attrs['colspan'].to_i; | |||
|
3726 | end | |||
|
3727 | if attrs['rowspan'].nil? or attrs['rowspan'] == '' | |||
|
3728 | rowspan = 1; | |||
|
3729 | else | |||
|
3730 | rowspan = attrs['rowspan'].to_i; | |||
|
3731 | end | |||
|
3732 | ||||
|
3733 | i = 0; | |||
|
3734 | while true | |||
|
3735 | next_i_distance = checkTableBlockingCellPosition(@table_id, @tr_id, @td_id + i); | |||
|
3736 | if next_i_distance == 0 | |||
|
3737 | @t_cells[@table_id][@tr_id].push "i0"=>@td_id + i, "j0"=>@tr_id, "i1"=>(@td_id + i + colspan - 1), "j1"=>@tr_id + rowspan - 1 | |||
|
3738 | break; | |||
|
3739 | end | |||
|
3740 | i += next_i_distance; | |||
|
3741 | end | |||
|
3742 | ||||
|
3743 | @t_columns += colspan; | |||
|
3744 | end | |||
|
3745 | end | |||
|
3746 | ||||
|
3747 | # | |||
|
3748 | # Calculate closing tags. | |||
|
3749 | # @param string :tag tag name (in upcase) | |||
|
3750 | # @access private | |||
|
3751 | # | |||
|
3752 | def closedHTMLTagCalc(tag) | |||
|
3753 | #Closing tag | |||
|
3754 | case (tag) | |||
|
3755 | when 'table' | |||
|
3756 | if @max_table_columns[@table_id] < @t_columns | |||
|
3757 | @max_table_columns[@table_id] = @t_columns; | |||
|
3758 | end | |||
|
3759 | @table_id += 1; | |||
|
3760 | @t_cells.push [] | |||
|
3761 | end | |||
|
3762 | end | |||
|
3763 | ||||
|
3764 | # | |||
3495 | # Process opening tags. |
|
3765 | # Process opening tags. | |
3496 | # @param string :tag tag name (in upcase) |
|
3766 | # @param string :tag tag name (in upcase) | |
3497 | # @param string :attr tag attribute (in upcase) |
|
3767 | # @param string :attr tag attribute (in upcase) | |
@@ -3501,20 +3771,56 class TCPDF | |||||
3501 | def openHTMLTagHandler(tag, attrs, fill=0) |
|
3771 | def openHTMLTagHandler(tag, attrs, fill=0) | |
3502 | #Opening tag |
|
3772 | #Opening tag | |
3503 | case (tag) |
|
3773 | case (tag) | |
|
3774 | when 'pre' | |||
|
3775 | @pre_state = true; | |||
|
3776 | @l_margin += 5; | |||
|
3777 | @r_margin += 5; | |||
|
3778 | @x += 5; | |||
|
3779 | ||||
3504 | when 'table' |
|
3780 | when 'table' | |
|
3781 | if @default_table_columns < @max_table_columns[@table_id] | |||
|
3782 | @table_columns = @max_table_columns[@table_id]; | |||
|
3783 | else | |||
|
3784 | @table_columns = @default_table_columns; | |||
|
3785 | end | |||
|
3786 | @l_margin += 5; | |||
|
3787 | @r_margin += 5; | |||
|
3788 | @x += 5; | |||
|
3789 | ||||
3505 | if attrs['border'].nil? or attrs['border'] == '' |
|
3790 | if attrs['border'].nil? or attrs['border'] == '' | |
3506 | @tableborder = 0; |
|
3791 | @tableborder = 0; | |
3507 | else |
|
3792 | else | |
3508 | @tableborder = attrs['border']; |
|
3793 | @tableborder = attrs['border']; | |
3509 | end |
|
3794 | end | |
3510 | when 'tr', 'td', 'th' |
|
3795 | @tr_id = -1; | |
3511 | # SetStyle('b', true) if tag == 'th' |
|
3796 | @max_td_page[0] = @page; | |
|
3797 | @max_td_y[0] = @y; | |||
3512 |
|
3798 | |||
|
3799 | when 'tr', 'td', 'th' | |||
|
3800 | if tag == 'th' | |||
|
3801 | SetStyle('b', true); | |||
|
3802 | @tdalign = "C"; | |||
|
3803 | end | |||
3513 | if ((!attrs['width'].nil?) and (attrs['width'] != '')) |
|
3804 | if ((!attrs['width'].nil?) and (attrs['width'] != '')) | |
3514 | @tdwidth = (attrs['width'].to_i/4); |
|
3805 | @tdwidth = (attrs['width'].to_i/4); | |
3515 | else |
|
3806 | else | |
3516 |
@tdwidth = ((@w - @l_margin - @r_margin) / @ |
|
3807 | @tdwidth = ((@w - @l_margin - @r_margin) / @table_columns); | |
3517 | end |
|
3808 | end | |
|
3809 | ||||
|
3810 | if tag == 'tr' | |||
|
3811 | @tr_id += 1; | |||
|
3812 | @td_id = -1; | |||
|
3813 | else | |||
|
3814 | @td_id += 1; | |||
|
3815 | @x = @l_margin + @tdwidth * @t_cells[@table_id][@tr_id][@td_id]['i0']; | |||
|
3816 | end | |||
|
3817 | ||||
|
3818 | if attrs['colspan'].nil? or attrs['border'] == '' | |||
|
3819 | @colspan = 1; | |||
|
3820 | else | |||
|
3821 | @colspan = attrs['colspan'].to_i; | |||
|
3822 | end | |||
|
3823 | @tdwidth *= @colspan; | |||
3518 | if ((!attrs['height'].nil?) and (attrs['height'] != '')) |
|
3824 | if ((!attrs['height'].nil?) and (attrs['height'] != '')) | |
3519 | @tdheight=(attrs['height'].to_i / @k); |
|
3825 | @tdheight=(attrs['height'].to_i / @k); | |
3520 | else |
|
3826 | else | |
@@ -3538,17 +3844,14 class TCPDF | |||||
3538 | @tdbegin=true; |
|
3844 | @tdbegin=true; | |
3539 |
|
3845 | |||
3540 | when 'hr' |
|
3846 | when 'hr' | |
3541 | Ln(); |
|
3847 | margin = 1; | |
3542 | if ((!attrs['width'].nil?) and (attrs['width'] != '')) |
|
3848 | if ((!attrs['width'].nil?) and (attrs['width'] != '')) | |
3543 | hrWidth = attrs['width']; |
|
3849 | hrWidth = attrs['width']; | |
3544 | else |
|
3850 | else | |
3545 | hrWidth = @w - @l_margin - @r_margin; |
|
3851 | hrWidth = @w - @l_margin - @r_margin - margin; | |
3546 | end |
|
3852 | end | |
3547 | x = GetX(); |
|
|||
3548 | y = GetY(); |
|
|||
3549 | SetLineWidth(0.2); |
|
|||
3550 | Line(x, y, x + hrWidth, y); |
|
|||
3551 | SetLineWidth(0.2); |
|
3853 | SetLineWidth(0.2); | |
|
3854 | Line(@x + margin, @y, @x + hrWidth, @y); | |||
3552 | Ln(); |
|
3855 | Ln(); | |
3553 |
|
3856 | |||
3554 | when 'strong' |
|
3857 | when 'strong' | |
@@ -3557,6 +3860,12 class TCPDF | |||||
3557 | when 'em' |
|
3860 | when 'em' | |
3558 | SetStyle('i', true); |
|
3861 | SetStyle('i', true); | |
3559 |
|
3862 | |||
|
3863 | when 'ins' | |||
|
3864 | SetStyle('u', true); | |||
|
3865 | ||||
|
3866 | when 'del' | |||
|
3867 | SetStyle('d', true); | |||
|
3868 | ||||
3560 | when 'b', 'i', 'u' |
|
3869 | when 'b', 'i', 'u' | |
3561 | SetStyle(tag, true); |
|
3870 | SetStyle(tag, true); | |
3562 |
|
3871 | |||
@@ -3565,6 +3874,8 class TCPDF | |||||
3565 |
|
3874 | |||
3566 | when 'img' |
|
3875 | when 'img' | |
3567 | if (!attrs['src'].nil?) |
|
3876 | if (!attrs['src'].nil?) | |
|
3877 | Write(@lasth, '!' + attrs['src'] + '!', '', fill); | |||
|
3878 | =begin Comment out. Because not implement image output yet. | |||
3568 | # replace relative path with real server path |
|
3879 | # replace relative path with real server path | |
3569 | attrs['src'] = attrs['src'].gsub(@@k_path_url_cache, @@k_path_cache); |
|
3880 | attrs['src'] = attrs['src'].gsub(@@k_path_url_cache, @@k_path_cache); | |
3570 | if (attrs['width'].nil?) |
|
3881 | if (attrs['width'].nil?) | |
@@ -3577,37 +3888,70 class TCPDF | |||||
3577 | Image(attrs['src'], GetX(),GetY(), pixelsToMillimeters(attrs['width']), pixelsToMillimeters(attrs['height'])); |
|
3888 | Image(attrs['src'], GetX(),GetY(), pixelsToMillimeters(attrs['width']), pixelsToMillimeters(attrs['height'])); | |
3578 | #SetX(@img_rb_x); |
|
3889 | #SetX(@img_rb_x); | |
3579 | SetY(@img_rb_y); |
|
3890 | SetY(@img_rb_y); | |
3580 |
|
3891 | =end | ||
3581 | end |
|
3892 | end | |
3582 |
|
3893 | |||
3583 | when 'ul' |
|
3894 | when 'ul', 'ol' | |
3584 | @listordered = false; |
|
3895 | if @li_count == 0 | |
3585 | @listcount = 0; |
|
3896 | Ln() if @prevquote_count == @quote_count; # insert Ln for keeping quote lines | |
3586 |
|
3897 | @prevquote_count = @quote_count; | ||
3587 | when 'ol' |
|
3898 | end | |
3588 |
|
|
3899 | if @li_state == true | |
3589 | @listcount = 0; |
|
3900 | Ln(); | |
|
3901 | @li_state = false; | |||
|
3902 | end | |||
|
3903 | if tag == 'ul' | |||
|
3904 | @list_ordered[@li_count] = false; | |||
|
3905 | else | |||
|
3906 | @list_ordered[@li_count] = true; | |||
|
3907 | end | |||
|
3908 | @list_count[@li_count] = 0; | |||
|
3909 | @li_count += 1 | |||
3590 |
|
3910 | |||
3591 | when 'li' |
|
3911 | when 'li' | |
3592 | Ln(); |
|
3912 | Ln() if @li_state == true | |
3593 | if (@listordered) |
|
3913 | if (@list_ordered[@li_count - 1]) | |
3594 |
|
|
3914 | @list_count[@li_count - 1] += 1; | |
3595 | @lispacer = " " + (@listcount).to_s + ". "; |
|
3915 | @li_spacer = " " * @li_count + (@list_count[@li_count - 1]).to_s + ". "; | |
3596 | else |
|
3916 | else | |
3597 | #unordered list simbol |
|
3917 | #unordered list simbol | |
3598 | @lispacer = " - "; |
|
3918 | @li_spacer = " " * @li_count + "- "; | |
3599 | end |
|
3919 | end | |
3600 | Write(@lasth, @lispacer, '', fill); |
|
3920 | Write(@lasth, @spacer + @li_spacer, '', fill); | |
|
3921 | @li_state = true; | |||
3601 |
|
3922 | |||
3602 |
when 'blockquote' |
|
3923 | when 'blockquote' | |
|
3924 | if (@quote_count == 0) | |||
|
3925 | SetStyle('i', true); | |||
|
3926 | @l_margin += 5; | |||
|
3927 | else | |||
|
3928 | @l_margin += 5 / 2; | |||
|
3929 | end | |||
|
3930 | @x = @l_margin; | |||
|
3931 | @quote_top[@quote_count] = @y; | |||
|
3932 | @quote_page[@quote_count] = @page; | |||
|
3933 | @quote_count += 1 | |||
|
3934 | when 'br' | |||
3603 | Ln(); |
|
3935 | Ln(); | |
3604 | if (@lispacer.length > 0) |
|
3936 | ||
3605 | @x += GetStringWidth(@lispacer); |
|
3937 | if (@li_spacer.length > 0) | |
|
3938 | @x += GetStringWidth(@li_spacer); | |||
3606 | end |
|
3939 | end | |
3607 |
|
3940 | |||
3608 | when 'p' |
|
3941 | when 'p' | |
3609 | Ln(); |
|
3942 | Ln(); | |
3610 | Ln(); |
|
3943 | 0.upto(@quote_count - 1) do |i| | |
|
3944 | if @quote_page[i] == @page; | |||
|
3945 | if @quote_top[i] == @y - @lasth; # fix start line | |||
|
3946 | @quote_top[i] = @y; | |||
|
3947 | end | |||
|
3948 | else | |||
|
3949 | if @quote_page[i] == @page - 1; | |||
|
3950 | @quote_page[i] = @page; # fix start line | |||
|
3951 | @quote_top[i] = @t_margin; | |||
|
3952 | end | |||
|
3953 | end | |||
|
3954 | end | |||
3611 |
|
3955 | |||
3612 | when 'sup' |
|
3956 | when 'sup' | |
3613 | currentfont_size = @font_size; |
|
3957 | currentfont_size = @font_size; | |
@@ -3648,6 +3992,7 class TCPDF | |||||
3648 | @lasth = @font_size * @@k_cell_height_ratio; |
|
3992 | @lasth = @font_size * @@k_cell_height_ratio; | |
3649 |
|
3993 | |||
3650 | when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' |
|
3994 | when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' | |
|
3995 | Ln(); | |||
3651 | headsize = (4 - tag[1,1].to_f) * 2 |
|
3996 | headsize = (4 - tag[1,1].to_f) * 2 | |
3652 | @tempfontsize = @font_size_pt; |
|
3997 | @tempfontsize = @font_size_pt; | |
3653 | SetFontSize(@font_size_pt + headsize); |
|
3998 | SetFontSize(@font_size_pt + headsize); | |
@@ -3665,19 +4010,63 class TCPDF | |||||
3665 | def closedHTMLTagHandler(tag) |
|
4010 | def closedHTMLTagHandler(tag) | |
3666 | #Closing tag |
|
4011 | #Closing tag | |
3667 | case (tag) |
|
4012 | case (tag) | |
|
4013 | when 'pre' | |||
|
4014 | @pre_state = false; | |||
|
4015 | @l_margin -= 5; | |||
|
4016 | @r_margin -= 5; | |||
|
4017 | @x = @l_margin; | |||
|
4018 | Ln(); | |||
|
4019 | ||||
3668 | when 'td','th' |
|
4020 | when 'td','th' | |
3669 | @tdbegin = false; |
|
4021 | @tdbegin = false; | |
3670 | @tdwidth = 0; |
|
4022 | @tdwidth = 0; | |
3671 | @tdheight = 0; |
|
4023 | @tdheight = 0; | |
3672 | @tdalign = "L"; |
|
4024 | @tdalign = "L"; | |
|
4025 | SetStyle('b', false); | |||
3673 | @tdfill = 0; |
|
4026 | @tdfill = 0; | |
3674 | SetFillColor(@prevfill_color[0], @prevfill_color[1], @prevfill_color[2]); |
|
4027 | SetFillColor(@prevfill_color[0], @prevfill_color[1], @prevfill_color[2]); | |
3675 |
|
4028 | |||
3676 | when 'tr' |
|
4029 | when 'tr' | |
3677 | Ln(); |
|
4030 | @y = @max_td_y[@tr_id + 1]; | |
|
4031 | @x = @l_margin; | |||
|
4032 | @page = @max_td_page[@tr_id + 1]; | |||
3678 |
|
4033 | |||
3679 | when 'table' |
|
4034 | when 'table' | |
|
4035 | # Write Table Line | |||
|
4036 | width = (@w - @l_margin - @r_margin) / @table_columns; | |||
|
4037 | 0.upto(@t_cells[@table_id].size - 1) do |j| | |||
|
4038 | 0.upto(@t_cells[@table_id][j].size - 1) do |i| | |||
|
4039 | @page = @max_td_page[j] | |||
|
4040 | i0=@t_cells[@table_id][j][i]['i0']; | |||
|
4041 | j0=@t_cells[@table_id][j][i]['j0']; | |||
|
4042 | i1=@t_cells[@table_id][j][i]['i1']; | |||
|
4043 | j1=@t_cells[@table_id][j][i]['j1']; | |||
|
4044 | ||||
|
4045 | Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * (i1+1), @max_td_y[j0]) # top | |||
|
4046 | if ( @page == @max_td_page[j1 + 1]) | |||
|
4047 | Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * i0, @max_td_y[j1+1]) # left | |||
|
4048 | Line(@l_margin + width * (i1+1), @max_td_y[j0], @l_margin + width * (i1+1), @max_td_y[j1+1]) # right | |||
|
4049 | else | |||
|
4050 | Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * i0, @page_break_trigger) # left | |||
|
4051 | Line(@l_margin + width * (i1+1), @max_td_y[j0], @l_margin + width * (i1+1), @page_break_trigger) # right | |||
|
4052 | @page += 1; | |||
|
4053 | while @page < @max_td_page[j1 + 1] | |||
|
4054 | Line(@l_margin + width * i0, @t_margin, @l_margin + width * i0, @page_break_trigger) # left | |||
|
4055 | Line(@l_margin + width * (i1+1), @t_margin, @l_margin + width * (i1+1), @page_break_trigger) # right | |||
|
4056 | @page += 1; | |||
|
4057 | end | |||
|
4058 | Line(@l_margin + width * i0, @t_margin, @l_margin + width * i0, @max_td_y[j1+1]) # left | |||
|
4059 | Line(@l_margin + width * (i1+1), @t_margin, @l_margin + width * (i1+1), @max_td_y[j1+1]) # right | |||
|
4060 | end | |||
|
4061 | Line(@l_margin + width * i0, @max_td_y[j1+1], @l_margin + width * (i1+1), @max_td_y[j1+1]) # bottom | |||
|
4062 | end | |||
|
4063 | end | |||
|
4064 | ||||
|
4065 | @l_margin -= 5; | |||
|
4066 | @r_margin -= 5; | |||
3680 | @tableborder=0; |
|
4067 | @tableborder=0; | |
|
4068 | Ln(); | |||
|
4069 | @table_id += 1; | |||
3681 |
|
4070 | |||
3682 | when 'strong' |
|
4071 | when 'strong' | |
3683 | SetStyle('b', false); |
|
4072 | SetStyle('b', false); | |
@@ -3685,12 +4074,21 class TCPDF | |||||
3685 | when 'em' |
|
4074 | when 'em' | |
3686 | SetStyle('i', false); |
|
4075 | SetStyle('i', false); | |
3687 |
|
4076 | |||
|
4077 | when 'ins' | |||
|
4078 | SetStyle('u', false); | |||
|
4079 | ||||
|
4080 | when 'del' | |||
|
4081 | SetStyle('d', false); | |||
|
4082 | ||||
3688 | when 'b', 'i', 'u' |
|
4083 | when 'b', 'i', 'u' | |
3689 | SetStyle(tag, false); |
|
4084 | SetStyle(tag, false); | |
3690 |
|
4085 | |||
3691 | when 'a' |
|
4086 | when 'a' | |
3692 | @href = nil; |
|
4087 | @href = nil; | |
3693 |
|
4088 | |||
|
4089 | when 'p' | |||
|
4090 | Ln(); | |||
|
4091 | ||||
3694 | when 'sup' |
|
4092 | when 'sup' | |
3695 | currentfont_size = @font_size; |
|
4093 | currentfont_size = @font_size; | |
3696 | SetFontSize(@tempfontsize); |
|
4094 | SetFontSize(@tempfontsize); | |
@@ -3725,14 +4123,47 class TCPDF | |||||
3725 | #@text_color = @prevtext_color; |
|
4123 | #@text_color = @prevtext_color; | |
3726 | @lasth = @font_size * @@k_cell_height_ratio; |
|
4124 | @lasth = @font_size * @@k_cell_height_ratio; | |
3727 |
|
4125 | |||
3728 |
when ' |
|
4126 | when 'blockquote' | |
3729 | Ln(); |
|
4127 | @quote_count -= 1 | |
|
4128 | if (@quote_page[@quote_count] == @page) | |||
|
4129 | Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @y) # quoto line | |||
|
4130 | else | |||
|
4131 | cur_page = @page; | |||
|
4132 | cur_y = @y; | |||
|
4133 | @page = @quote_page[@quote_count]; | |||
|
4134 | if (@quote_top[@quote_count] < @page_break_trigger) | |||
|
4135 | Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @page_break_trigger) # quoto line | |||
|
4136 | end | |||
|
4137 | @page += 1; | |||
|
4138 | while @page < cur_page | |||
|
4139 | Line(@l_margin - 1, @t_margin, @l_margin - 1, @page_break_trigger) # quoto line | |||
|
4140 | @page += 1; | |||
|
4141 | end | |||
|
4142 | @y = cur_y; | |||
|
4143 | Line(@l_margin - 1, @t_margin, @l_margin - 1, @y) # quoto line | |||
|
4144 | end | |||
|
4145 | if (@quote_count <= 0) | |||
|
4146 | SetStyle('i', false); | |||
|
4147 | @l_margin -= 5; | |||
|
4148 | else | |||
|
4149 | @l_margin -= 5 / 2; | |||
|
4150 | end | |||
|
4151 | @x = @l_margin; | |||
|
4152 | Ln() if @quote_count == 0 | |||
3730 |
|
4153 | |||
3731 | when 'ol' |
|
4154 | when 'ul', 'ol' | |
|
4155 | @li_count -= 1 | |||
|
4156 | if @li_state == true | |||
3732 | Ln(); |
|
4157 | Ln(); | |
|
4158 | @li_state = false; | |||
|
4159 | end | |||
3733 |
|
4160 | |||
3734 | when 'li' |
|
4161 | when 'li' | |
3735 | @lispacer = ""; |
|
4162 | @li_spacer = ""; | |
|
4163 | if @li_state == true | |||
|
4164 | Ln(); | |||
|
4165 | @li_state = false; | |||
|
4166 | end | |||
3736 |
|
4167 | |||
3737 | when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' |
|
4168 | when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' | |
3738 | SetFontSize(@tempfontsize); |
|
4169 | SetFontSize(@tempfontsize); | |
@@ -3741,6 +4172,16 class TCPDF | |||||
3741 | Ln(); |
|
4172 | Ln(); | |
3742 | @lasth = @font_size * @@k_cell_height_ratio; |
|
4173 | @lasth = @font_size * @@k_cell_height_ratio; | |
3743 |
|
|
4174 | ||
|
4175 | if tag == 'h1' or tag == 'h2' or tag == 'h3' or tag == 'h4' | |||
|
4176 | margin = 1; | |||
|
4177 | hrWidth = @w - @l_margin - @r_margin - margin; | |||
|
4178 | if tag == 'h1' or tag == 'h2' | |||
|
4179 | SetLineWidth(0.2); | |||
|
4180 | else | |||
|
4181 | SetLineWidth(0.1); | |||
|
4182 | end | |||
|
4183 | Line(@x + margin, @y, @x + hrWidth, @y); | |||
|
4184 | end | |||
3744 | end |
|
4185 | end | |
3745 | end |
|
4186 | end | |
3746 |
|
4187 | |||
@@ -3752,11 +4193,16 class TCPDF | |||||
3752 | # |
|
4193 | # | |
3753 | def SetStyle(tag, enable) |
|
4194 | def SetStyle(tag, enable) | |
3754 | #Modify style and select corresponding font |
|
4195 | #Modify style and select corresponding font | |
3755 | style=''; |
|
4196 | ['b', 'i', 'u', 'd'].each do |s| | |
3756 | ['b', 'i', 'u'].each do |s| |
|
4197 | if tag.downcase == s | |
3757 | style << s if tag.downcase == s and enable |
|
4198 | if enable | |
|
4199 | @style << s if ! @style.include?(s) | |||
|
4200 | else | |||
|
4201 | @style = @style.gsub(s,'') | |||
|
4202 | end | |||
|
4203 | end | |||
3758 | end |
|
4204 | end | |
3759 | SetFont('', style); |
|
4205 | SetFont('', @style); | |
3760 | end |
|
4206 | end | |
3761 |
|
4207 | |||
3762 | # |
|
4208 | # |
General Comments 0
You need to be logged in to leave comments.
Login now