Recent

Author Topic: Question on text style  (Read 5965 times)

stab

  • Full Member
  • ***
  • Posts: 234
Question on text style
« on: January 08, 2021, 02:31:52 pm »
Hi,

I'm trying to use fpVectorial to create an odt-file to test how to set
text parameters like bold, italic,  strikethrough and font color.

The only thing that seem to work is bold and italic text.

My code:
Code: Pascal  [Select][+][-]
  1. procedure TfrmODTHandler.Button1Click(Sender: TObject);
  2. var
  3.   Document : TvVectorialDocument;
  4.   Page : TvTextPageSequence;
  5.   Paragraph : TvParagraph;
  6.   BoldTextStyle : TvStyle;
  7.   StrikeThroughTextStyle : TvStyle;
  8. begin
  9.   Document := TvVectorialDocument.Create;
  10.   try
  11.     //  Adds the defaut Paragraph Styles
  12.     //    StyleTextBody, StyleHeading1,
  13.     //    StyleHeading2 & StyleHeading3
  14.     Document.AddStandardTextDocumentStyles(vfODT);
  15.  
  16.      // Add our own Style
  17.     BoldTextStyle := Document.AddStyle();
  18.     BoldTextStyle.Kind := vskTextSpan;
  19.     BoldTextStyle.Name := 'Bold';
  20.     BoldTextStyle.Font.Bold := true;
  21.     BoldTextStyle.Font.Italic := true;
  22.     BoldTextStyle.Font.Color := TColorToFPColor(clRed);
  23.     BoldTextStyle.SetElements := BoldTextStyle.SetElements +
  24.       [spbfFontBold, spbfFontItalic, spbfFontColor];
  25.  
  26.     StrikeThroughTextStyle := Document.AddStyle();
  27.     StrikeThroughTextStyle.Kind := vskTextSpan;
  28.     StrikeThroughTextStyle.Name := 'StrikeThrough';
  29.     StrikeThroughTextStyle.Font.StrikeThrough := true;
  30.     StrikeThroughTextStyle.SetElements := StrikeThroughTextStyle.SetElements +
  31.       [spbfFontStrikeThrough];
  32.  
  33.     Page := Document.AddTextPageSequence;
  34.     Paragraph := Page.AddParagraph;
  35.     Paragraph.AddText('Hello ').Style := StrikeThroughTextStyle;
  36.     Paragraph.AddText('world').Style := BoldTextStyle;
  37.  
  38.     Document.WriteToFile('Hello world.odt', vfODT);
  39.   finally
  40.     Document.Free;
  41.   end;
  42. end;


Am I doing something wrong or isn't it possible to change text color and make a strikethrough? %)

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Question on text style
« Reply #1 on: January 08, 2021, 03:16:55 pm »
I think you are right, the attributes 'fo:color' for the text color and 'style:text-line-through-style' for strike-through text are not found in the ods writer unit.

You can file a bug report, but since nobody is working on this package, you'll have to wait for a while... Or you try to fix it yourself. It should not be too difficult: Using LibreOffice Writer create a document with a few words only, put one word in bold, and another one in some well-defined color. Since odt files are renamed zip files you can open the file contents if you rename the file to .zip and unzip it. You'll get some folders and some xml files. Find "content.xml" and open it in a text editor or, better, in an xml viewer (for better formatting) and find where the text color style is stored. Compare with how bold is stored. (If you have an unzip gui like 7zip you can achieve all this within this GUI after a simple right-click in the explorer) Then open the fpvectorial odt writer unit and find where the text styles are stored. Extend the code such that text color is written analogous to the bold style using the node names found in the odt file.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question on text style
« Reply #2 on: January 09, 2021, 05:09:02 pm »
Thank you for your suggestion. Managed to add odt-functionality for underline, color and
strikeThrough :D

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Question on text style
« Reply #3 on: January 09, 2021, 05:13:13 pm »
Would you mind to publish your work? This way others can take advantage of your work. T5hat's the power of open source. Write a bug report (feature request), extract a patch from the changed unit(s) and add it to the report. Or simply upload the (zipped) changed units here, I can have a look and will apply to trunk if the changes are good.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question on text style
« Reply #4 on: January 09, 2021, 05:28:28 pm »
Actually I wanted to send my changes done in unit odtvectorialwriter.pas to Felipe Monteiro de Carvalho as he seems to be the one that has done most work. Perhaps my changes are not done
so well and I thougth Felipe could straighten my code.
I don't understand how to write a bug report but it is good if you could have a look at my code.
I've surrounded my changes with "// changes by stab"

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Question on text style
« Reply #5 on: January 09, 2021, 06:00:23 pm »
Felipe is rather inactive these days. So it is probably faster when I review your code; I've done the wmf and some svg work so that fpvectorial is not completely new to me.

Do you have a sample application which creates a test dcoument, ideally a simple console application like fpvTextWriteTest?
« Last Edit: January 09, 2021, 06:28:38 pm by wp »

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question on text style
« Reply #6 on: January 09, 2021, 07:50:56 pm »
OK, here comes a sample application

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Question on text style
« Reply #7 on: January 10, 2021, 12:46:55 am »
Thank you. I applied your code with minor modifications.

 

TinyPortal © 2005-2018