Paste the Chinese is garbled

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
th9999
Posts: 35
Joined: Tue Jun 25, 2013 10:42 am

Paste the Chinese is garbled

Post by th9999 »

Clerk hello:
Excuse me, recently a lot of customer response, my ScaleRichView when using paste, if the Chinese content, paste it is garbled,
thank you
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) What version of Delphi do you use?
2) From what application do you copy?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I read your answer.
You use non-Unicode version of Delphi, so, by default, text in ScaleRichView content is not Unicode. TRichView and ScaleRichView require to be Unicode to handle Chinese text properly.
You copies text from MS Word, so, copying occurs in RTF format.

I suggest to call this code to convert content of TSRichViewEdit to Unicode:

Code: Select all

procedure ConvertRVDataToUnicode(RVData: TCustomRVData);
var
  i, R, c, StyleNo: Integer;
  table:            TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount - 1 do
  begin
    StyleNo := RVData.GetItemStyle(i);
    if StyleNo >= 0 then
    begin
      if not RVData.GetRVStyle.TextStyles[StyleNo].Unicode then
      begin
        RVData.SetItemTextR(i, RVU_GetRawUnicode(RVData.GetItemTextW(i)));
        Include(RVData.GetItem(i).ItemOptions, rvioUnicode);
      end;
    end
    else if RVData.GetItem(i) is TRVTableItemInfo then
    begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for R := 0 to table.Rows.Count - 1 do
        for c := 0 to table.Rows[R].Count - 1 do
          if table.Cells[R, c] <> nil then
            ConvertRVDataToUnicode(table.Cells[R, c].GetRVData);
    end;
  end;
end;

procedure ConvertRVToUnicode(rv: TCustomRichView);
var
  i: Integer;
begin
  ConvertRVDataToUnicode(rv.RVData);
  for i := 0 to rv.Style.TextStyles.Count - 1 do
    rv.Style.TextStyles[i].Unicode := True;
end;

procedure ConvertSRVToUnicode(srv: TSRichViewEdit);
var
  HF: TSRVHeaderFooterType;
begin
  for HF := Low(TSRVHeaderFooterType) to High(TSRVHeaderFooterType) do
    ConvertRVDataToUnicode(srv.SubDocuments[HF]);
  ConvertRVToUnicode(srv.RichViewEdit);
  ConvertRVToUnicode(srv.RVHeader);
  ConvertRVToUnicode(srv.RVFooter);
  srv.RTFReadProperties.UnicodeMode := rvruOnlyUnicode;
end;
Call ConvertSRVToUnicode to convert your TSRichViewEdit control to Unicode when the application starts. If your application loads RVF files, you need to call this function after loading as well.
If TSRichViewEdit is already displayed, call SRichViewEdit.Format after this procedure.
th9999
Posts: 35
Joined: Tue Jun 25, 2013 10:42 am

TSRVHeaderFooterType

Post by th9999 »

TSRVHeaderFooterType need to refer to the unit
th9999
Posts: 35
Joined: Tue Jun 25, 2013 10:42 am

TSRVHeaderFooterType

Post by th9999 »

Thank you, can you tell me the TSRVHeaderFooterType need the unit, I won't compile
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you use the older version, without SubDocuments property, the last procedure must be

Code: Select all

procedure ConvertSRVToUnicode(srv: TSRichViewEdit); 
begin 
  ConvertRVToUnicode(srv.RichViewEdit); 
  ConvertRVToUnicode(srv.RVHeader); 
  ConvertRVToUnicode(srv.RVFooter); 
  srv.RTFReadProperties.UnicodeMode := rvruOnlyUnicode; 
end;
th9999
Posts: 35
Joined: Tue Jun 25, 2013 10:42 am

Thank you

Post by th9999 »

Thank you, I try!
Post Reply