View Issue Details

IDProjectCategoryView StatusLast Update
0036231FPCDatabasepublic2019-11-05 18:42
ReporterZdravko GabrovskiAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.3.1Product Buildfcldb - trunk 
Target VersionFixed in Version3.3.1 
Summary0036231: TRTFExporter enhancement
DescriptionWhen you try to export any kind of text data, that contains a non-ascii unicode characters (for example - cyrillic symbols), it is not possible to open a document into Microsoft word.
Word reports that a document is corrupted.
The reason is, that RTF format native does not support UTF8 character encoding.
The only way to avoid this is to replace that kind of symbols with combination of \uxxxxxxx?, where xxxx is a symbol code in Unicode format.

My proposal is to replace a existing code of method
function TCustomRTFExporter.EscapeRTF(S: String): String; (fprtxexport.pas, line111)

With following one:
function TCustomRTFExporter.EscapeRTF(S: String): String;
var
  SS : UnicodeString;
  Ch : UnicodeChar;
begin
  SS := UTF8Decode( S );
  Result := '';
  For Ch in SS do begin
    if Ch In ['{', '}', '\'] then
      Result := Result + '\';
    if Ord( Ch ) > 255 then
      Result := Result +'\u'+Ord( Ch ).ToString+'?'
    else
      Result := Result + Utf8Encode( Ch );
    end;
end;

This fix a problem and everything is OK.
Steps To ReproduceAs described above.
TagsNo tags attached.
Fixed in Revision43356
FPCOldBugId
FPCTarget3.2.0
Attached Files

Activities

Bart Broersma

2019-10-30 17:06

reporter   ~0118934

Last edited: 2019-10-30 17:08

View 2 revisions

Wouldn't that only work if S was actually encoded as UTF8 (so it would work in Lazarus, but not ia a plain fpc program with standard Windows codepage)?

From the docs: "UTF8Decode converts the UTF-8 encoded ansistring S to a unicodestring and returns the resulting string."

Michael Van Canneyt

2019-11-02 12:43

administrator   ~0118976

Fixed as suggested. The export routines now explicitly specify UTF8 as the string format.
Please test and close if OK.

Zdravko Gabrovski

2019-11-05 18:42

reporter   ~0119079

Works perfect, many thanks for the quick implementation!

Issue History

Date Modified Username Field Change
2019-10-30 08:51 Zdravko Gabrovski New Issue
2019-10-30 17:06 Bart Broersma Note Added: 0118934
2019-10-30 17:08 Bart Broersma Note Edited: 0118934 View Revisions
2019-11-02 10:16 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-11-02 10:16 Michael Van Canneyt Status new => assigned
2019-11-02 12:43 Michael Van Canneyt Status assigned => resolved
2019-11-02 12:43 Michael Van Canneyt Resolution open => fixed
2019-11-02 12:43 Michael Van Canneyt Fixed in Version => 3.3.1
2019-11-02 12:43 Michael Van Canneyt Fixed in Revision => 43356
2019-11-02 12:43 Michael Van Canneyt FPCTarget => 3.2.0
2019-11-02 12:43 Michael Van Canneyt Note Added: 0118976
2019-11-05 18:42 Zdravko Gabrovski Status resolved => closed
2019-11-05 18:42 Zdravko Gabrovski Note Added: 0119079