Changeset 380

Show
Ignore:
Timestamp:
Wed Mar 5 15:09:29 2008
Author:
Brian
Message:

Change html export script to always use utf-8

Files:

Legend:

Unmodified
Added
Removed
Modified
  • scripts/trunk/Print - Export/Export as HTML.py

    r276 r380  
    1 1 # Export as HTML.py  
    2   # Copyright 2004, 2005 by Brian C. Christensen  
      2 # Copyright 2004, 2005, 2008 by Brian C. Christensen  
    2 2  
    3 3 #    This file is part of GanttPV.  
     
    33 33 # 060902 - Alex - indent subtask names  
    34 34 # 060914 - Alex - use time-scale headers from Data (takes advantage of the better-looking headers in v0.7)  
      35 # 080305 - Brian - always export as utf-8  
    35 36  
    36 37 # Note: The fonts used in this script are larger than in GanttPV. To reduce font size to more closely match GanttPV, change the "font-size" lines in the header strings.  
     
    49 50 indent = " " * 3  
    50 51  
    51   xchar = { }  
    52   if convert:  
    53       cset = "windows-1257"  
    54       xchar = {  
    55           u'\u0105': '\xe0',  
    56           u'\u010C': '\xd0',  
    57           u'\u010D': '\xe8',  
    58           u'\u0117': '\xeb',  
    59           u'\u012F': '\xe1',  
    60           u'\u0160': '\xd0',  
    61           u'\u0161': '\xf0',  
    62           u'\u016B': '\xfb',  
    63           u'\u0173': '\xf8',  
    64           u'\u017E': '\xfe',  
    65           }  
    66   else:  
    67       cset = "iso-8859-1"  
      52 ##xchar = { }  
      53 ##if convert:  
      54 ##    cset = "windows-1257"  
      55 ##    xchar = {  
      56 ##        u'\u0105': '\xe0',  
      57 ##        u'\u010C': '\xd0',  
      58 ##        u'\u010D': '\xe8',  
      59 ##        u'\u0117': '\xeb',  
      60 ##        u'\u012F': '\xe1',  
      61 ##        u'\u0160': '\xd0',  
      62 ##        u'\u0161': '\xf0',  
      63 ##        u'\u016B': '\xfb',  
      64 ##        u'\u0173': '\xf8',  
      65 ##        u'\u017E': '\xfe',  
      66 ##        }  
      67 ##else:  
      68 ##    cset = "iso-8859-1"  
      69  
      70 cset = "utf-8"  # alway export as utf-8  
    68 71  
    69 72 if wrapcells:  
     
    86 89         result = str(value)  
    87 90     else:  
    88           result = "?"  
    89           try:  
    90               result = str(value)  
    91           except UnicodeEncodeError:  # fix european conversion errors  
    92               result = ''  
    93               for ch in value:  
    94                   if ord(ch) < 128:  
    95                       ch = chr(ord(ch))  
    96                   elif ch in '><"&':  
    97                       ch = "&#" + chr(ord(ch)) + ";"  
    98                   elif xchar.has_key(ch):  
    99                       ch = xchar[ch]  
    100                       #if len(xchar[ch]) == 1:  
    101                       #    xchar[ch]  
    102                       #    # ch = "&#" + chr(ord(xchar[ch])) + ";"  
    103                       #else:  
    104                       #    ch = xchar[ch]  
    105                   elif ord(ch) >= 128 and ord(ch) < 255:  
    106                       ch = "&#" + chr(ord(ch)) + ";"  
    107                   else:  
    108                       ch = "?"  
    109                   result += ch  
      91 ##        result = "?"  
      92 ##        try:  
      93         result = value.encode( "utf-8" )  
      94 ##        except UnicodeEncodeError:  # fix european conversion errors  
      95 ##            result = ''  
      96 ##            for ch in value:  
      97 ##                if ord(ch) < 128:  
      98 ##                    ch = chr(ord(ch))  
      99 ##                elif ch in '><"&':  
      100 ##                    ch = "&#" + chr(ord(ch)) + ";"  
      101 ##                elif xchar.has_key(ch):  
      102 ##                    ch = xchar[ch]  
      103 ##                    #if len(xchar[ch]) == 1:  
      104 ##                    #    xchar[ch]  
      105 ##                    #    # ch = "&#" + chr(ord(xchar[ch])) + ";"  
      106 ##                    #else:  
      107 ##                    #    ch = xchar[ch]  
      108 ##                elif ord(ch) >= 128 and ord(ch) < 255:  
      109 ##                    ch = "&#" + chr(ord(ch)) + ";"  
      110 ##                else:  
      111 ##                    ch = "?"  
      112 ##                result += ch  
    110 113     return result  
    111 114