SaveHTMLToStreamEx does not keep text alignment

General TRichView support forum. Please post your questions here
Post Reply
gdemers_logilys
Posts: 13
Joined: Mon Jun 16, 2014 1:10 pm

SaveHTMLToStreamEx does not keep text alignment

Post by gdemers_logilys »

I use SaveHTMLToStreamEx to export to html to use on a website.

I edit a paragraph to change its alignment to rvaRight. When I use SaveHTMLToStreamEx, the html paragraph has this : text-align: left;

Is there an option for this ?
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SaveHTMLToStreamEx does not keep text alignment

Post by Sergey Tkachenko »

How can I reproduce this problem?
I tested with ActionTest: File | New, typed a text, aligned to the right side, saved as HTML.
The result is attached.
Attachments
RightTest.zip
(592 Bytes) Downloaded 1497 times
gdemers_logilys
Posts: 13
Joined: Mon Jun 16, 2014 1:10 pm

Re: SaveHTMLToStreamEx does not keep text alignment

Post by gdemers_logilys »

Alright, I found my problem, but I don't know what to do with it. It has nothing to do with SaveHTMLToStreamEx.

I have some Code to remove empty lines from my text. I took this code from this forum a while ago. When I do it, I lose all alignments.

Here is my code :

Code: Select all

procedure TfStdFrameRichEditor.ClearEmptyLines(Sender: TObject);
var
  StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, NbDeletedLines: Integer;

  procedure DeleteBlankLines(RVData: TCustomRVData);
  var
    i,r,c: Integer;
    table: TRVTableItemInfo;
  begin
    for i := EndItemNo downto StartItemNo do begin //RVData.ItemCount-1 downto 0 do begin
      if RVData.IsParaStart(i)
      and (RVData.GetItemStyle(i)>=0)
      and ((Trim(RVData.GetItemText(i))='') or (Trim(RVData.GetItemText(i))=Char(160)))
      and (RVData.ItemCount>1) then begin
        RVData.DeleteItems(i,1);
        Inc(NbDeletedLines);
      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) and (table.IsCellSelected(r,c)) then
              DeleteBlankLines(table.Cells[r,c].GetRVData);
      end;
    end;
  end;

begin
  try
    RichView.ApplyParaStyle(0);

    NbDeletedLines := 0;
    RichView.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, True);

    DeleteBlankLines(RichView.RVData);
    NormalizeRichView(RichView.RVData);
    RichView.ClearUndo;
    RichView.Format;

    if NbDeletedLines > 0 then begin
      RichView.SetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo - NbDeletedLines, EndItemOffs);
      RichViewChange(RichView);
    end;
  except
  end;
end;
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SaveHTMLToStreamEx does not keep text alignment

Post by Sergey Tkachenko »

This function is from here: https://www.trichview.com/forums/viewtopic.php?f=3&t=66

And yes, this function is dangerous so I modified it.
It deleted empty text items from the beginning of paragraphs, but did not check that these items are the only items in the paragraphs. Normally, it must be so, unless you use EmptyWidth feature). But documents might be not completely correct/optimal, so empty text items may be followed by other content in the same paragraph. Some additional code is needed to delete an item starting a multiitem paragraph, not just a call of DeleteItems.

I modified a code so it checks if this item is the only item in the paragraph.

To optimize document (including deletion of empty text items from multiitem paragraphs), call NormalizeRichView function from RVNormalize unit.
Post Reply