Forum > FPvectorial

Question on text style

(1/2) > >>


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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmODTHandler.Button1Click(Sender: TObject);var  Document : TvVectorialDocument;  Page : TvTextPageSequence;  Paragraph : TvParagraph;  BoldTextStyle : TvStyle;  StrikeThroughTextStyle : TvStyle;begin  Document := TvVectorialDocument.Create;  try    //  Adds the defaut Paragraph Styles    //    StyleTextBody, StyleHeading1,    //    StyleHeading2 & StyleHeading3    Document.AddStandardTextDocumentStyles(vfODT);      // Add our own Style    BoldTextStyle := Document.AddStyle();    BoldTextStyle.Kind := vskTextSpan;    BoldTextStyle.Name := 'Bold';    BoldTextStyle.Font.Bold := true;    BoldTextStyle.Font.Italic := true;    BoldTextStyle.Font.Color := TColorToFPColor(clRed);    BoldTextStyle.SetElements := BoldTextStyle.SetElements +      [spbfFontBold, spbfFontItalic, spbfFontColor];     StrikeThroughTextStyle := Document.AddStyle();    StrikeThroughTextStyle.Kind := vskTextSpan;    StrikeThroughTextStyle.Name := 'StrikeThrough';    StrikeThroughTextStyle.Font.StrikeThrough := true;    StrikeThroughTextStyle.SetElements := StrikeThroughTextStyle.SetElements +      [spbfFontStrikeThrough];     Page := Document.AddTextPageSequence;    Paragraph := Page.AddParagraph;    Paragraph.AddText('Hello ').Style := StrikeThroughTextStyle;    Paragraph.AddText('world').Style := BoldTextStyle;     Document.WriteToFile('Hello world.odt', vfODT);  finally    Document.Free;  end;end;

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

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.

Thank you for your suggestion. Managed to add odt-functionality for underline, color and
strikeThrough :D

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.

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"


[0] Message Index

[#] Next page

Go to full version