Page 1 of 1

Paste the Chinese is garbled

Posted: Fri Apr 08, 2016 3:39 am
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

Posted: Fri Apr 08, 2016 8:46 am
by Sergey Tkachenko
1) What version of Delphi do you use?
2) From what application do you copy?

Posted: Fri Apr 08, 2016 1:50 pm
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.

TSRVHeaderFooterType

Posted: Fri Apr 08, 2016 11:45 pm
by th9999
TSRVHeaderFooterType need to refer to the unit

TSRVHeaderFooterType

Posted: Sat Apr 09, 2016 12:04 am
by th9999
Thank you, can you tell me the TSRVHeaderFooterType need the unit, I won't compile

Posted: Sat Apr 09, 2016 8:26 am
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;

Thank you

Posted: Sat Apr 09, 2016 8:29 am
by th9999
Thank you, I try!