trichview.com

trichview.support.examples




Example: converting document to Unicode


Return to index


Author

Message

Sergey Tkachenko

Posted: 12/14/2002 0:05:23


RichView documents can contain mixed contents - both Unicode and single-byte

text.

The code below converts all single-byte text in the document to Unicode:


uses RichView, RVTable, CRVData, RVUni;


// internal procedure

procedure ConvertRVToUnicode(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.SetItemText(i, RVU_GetRawUnicode(RVData.GetItemTextW(i)));

        Include(RVData.GetItem(i).ItemOptions, rvioUnicode);

      end;

      end

    else if RVData.GetItemStyle(i)=rvsTable 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

            ConvertRVToUnicode(table.Cells[r,c].GetRVData);

    end;

  end;

end;


// main procedure

procedure ConvertToUnicode(rv: TCustomRichView);

var i: Integer;

begin

  ConvertRVToUnicode(rv.RVData);

  for i := 0 to rv.Style.TextStyles.Count-1 do

    rv.Style.TextStyles[i].Unicode := True;

end;


Call

RichViewEdit1.ClearUndo;

ConvertToUnicode(RichViewEdit1);


RVStyle object must be used exclusively by the given RichView (RichViewEdit1

in this example), otherwise documents in other RichViews linked to the same

RVStyle will be corrupted.


Text is converted basing on its Charset. If Charset = DEFAULT_CHARSET,

conversion is based on RVStyle.DefCodePage (main system language by default)





Powered by ABC Amber Outlook Express Converter