Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # -*- coding:utf8 -*-
  2. """
  3. this is tool script which help fix chinese messy code
  4. when using python reportLab library convert html to pdf.
  5. DO NOT CHANGE IT.
  6.  
  7. usage:
  8. import it at beginning of other class file where use reportlab/xhtml2pdf
  9. i.e. {{from core.utils.encode import *}}
  10. """
  11.  
  12. import reportlab.rl_config
  13. reportlab.rl_config.warnOnMissingFontGlyphs = 0
  14.  
  15. import reportlab.pdfbase.pdfmetrics
  16. import reportlab.pdfbase.ttfonts
  17. from django.conf import settings
  18.  
  19.  
  20. reportlab.pdfbase.pdfmetrics.registerFont(
  21. reportlab.pdfbase.ttfonts.TTFont('simsun', '%s/fonts/simsun.ttf' % settings.PROJECT_STATIC_ROOT))
  22.  
  23. import reportlab.lib.fonts
  24.  
  25. reportlab.lib.fonts.ps2tt = lambda psfn: ('simsun', 0, 0)
  26. reportlab.lib.fonts.tt2ps = lambda fn, b, i: 'simsun'
  27. import reportlab.platypus
  28.  
  29.  
  30. def wrap(self, availWidth, availHeight):
  31. # work out widths array for breaking
  32. self.width = availWidth
  33. leftIndent = self.style.leftIndent
  34. first_line_width = availWidth - (leftIndent + self.style.firstLineIndent) - self.style.rightIndent
  35. later_widths = availWidth - leftIndent - self.style.rightIndent
  36. try:
  37. self.blPara = self.breakLinesCJK([first_line_width, later_widths])
  38. except:
  39. self.blPara = self.breakLines([first_line_width, later_widths])
  40. self.height = len(self.blPara.lines) * self.style.leading
  41. return (self.width, self.height)
  42.  
  43.  
  44. reportlab.platypus.Paragraph.wrap = wrap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement