@@ -122,7 +122,7 @@ def self.rtf2text str, format=:text
122
122
end
123
123
end
124
124
125
- RTF_PREBUF =
125
+ RTF_PREBUF =
126
126
"{\\ rtf1\\ ansi\\ mac\\ deff0\\ deftab720{\\ fonttbl;}" \
127
127
"{\\ f0\\ fnil \\ froman \\ fswiss \\ fmodern \\ fscript " \
128
128
"\\ fdecor MS Sans SerifSymbolArialTimes New RomanCourier" \
@@ -175,7 +175,7 @@ def rtfdecompr data
175
175
else # unknown magic number
176
176
raise "Unknown compression type (magic number 0x%08x)" % magic
177
177
end
178
-
178
+
179
179
# not sure if its due to a bug in the above code. doesn't seem to be
180
180
# in my tests, but sometimes there's a trailing null. we chomp it here,
181
181
# which actually makes the resultant rtf smaller than its advertised
@@ -189,7 +189,7 @@ def rtfdecompr data
189
189
#
190
190
# Returns +nil+ if it doesn't look like an rtf encapsulated rtf.
191
191
#
192
- # Some cases that the original didn't deal with have been patched up, eg from
192
+ # Some cases that the original didn't deal with have been patched up, eg from
193
193
# this chunk, where there are tags outside of the htmlrtf ignore block.
194
194
#
195
195
# "{\\*\\htmltag116 <br />}\\htmlrtf \\line \\htmlrtf0 \\line {\\*\\htmltag84 <a href..."
@@ -229,8 +229,14 @@ def rtfdecompr data
229
229
def rtf2html rtf
230
230
scan = StringScanner . new rtf
231
231
# require \fromhtml. is this worth keeping? apparently you see \\fromtext if it
232
- # was converted from plain text.
232
+ # was converted from plain text.
233
233
return nil unless rtf [ "\\ fromhtml" ]
234
+ if scan . scan_until ( /\\ ansicpg/ )
235
+ code_page = "cp" + scan . scan ( /\d +/ )
236
+ scan . pos = 0
237
+ else
238
+ code_page = 'ascii'
239
+ end
234
240
html = ''
235
241
ignore_tag = nil
236
242
# skip up to the first htmltag. return nil if we don't ever find one
@@ -270,7 +276,7 @@ def rtf2html rtf
270
276
p :wtf
271
277
end
272
278
end
273
- html . strip . empty? ? nil : html
279
+ html . strip . empty? ? nil : html . encode ( 'utf-8' , code_page )
274
280
end
275
281
276
282
module_function :rtf2html , :rtfdecompr
0 commit comments