Forum > FPvectorial

The problem of drawing lines(fpvectorial)

(1/2) > >>

jianwt:
I'm a beginner and I want to ask a question. I want to draw two horizontal line segments (left to right) using fpvector that do not overlap by 3cm from the top of the document. It's like drawing lines in WORD.
Thank you for your help
(Code is the official code. I'm just using it to illustrate my needs.)

wp:
When I run your code I don't see the issue. Please post code so that I can reproduce and work on it.

KodeZwerg:

--- Quote from: jianwt on January 26, 2023, 10:58:32 am ---I'm a beginner and I want to ask a question.
--- End quote ---
Please put your code into a better readable way by adding the proper tags around.
How? Very easy. Use Forums [ # ] button and insert your code between the tags.

jianwt:
My requirement is to draw 2 horizontal lines in the doc using fpvectorial.
(Code is the official code. I'm just using it to illustrate my needs.)
Look at the picture. Thank you,

--- 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";}};} --- unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  fpvectorialpkg,  fpvectorial,  fpvutils   // For RGBToFPColor()  ; type //type  { TvTableHelper }  TvTableHelper = class helper for TvTable  public    function AddColWidth(AValue: Double): Integer;  end;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm}   { TvTableHelper } function TvTableHelper.AddColWidth(AValue: Double): Integer;begin  SetLength(ColWidths, Length(ColWidths) + 1);  ColWidths[High(ColWidths)] := AValue;  Result := 0;end; { TForm1 }procedure TForm1.Button1Click(Sender: TObject);var  Document: TvVectorialDocument;  Page: TvTextPageSequence;  Paragraph: TvParagraph;  BoldTextStyle: TvStyle;  CenterStyle: TvStyle;  Table: TvTable;  Row: TvTableRow; // Col:TvTablecol;  Cell: TvTableCell;  iRow: Integer;  iCol: Integer; const  // Most dimensions in FPVectorial are in mm.  If you want to specify  // anything in other units, be ready to do the conversion...  ONE_POINT_IN_MM = 0.35278; begin  Document := TvVectorialDocument.Create;  try    //  Adds the defaut Paragraph Styles    //    StyleTextBody, StyleHeading1,    //    StyleHeading2 & StyleHeading3    Document.AddStandardTextDocumentStyles(vfUnknown);     // Add our own Style for bolded text elements    BoldTextStyle := Document.AddStyle();    BoldTextStyle.Kind := vskTextSpan; // This style will only be applied to selected Text Spans    BoldTextStyle.Name := 'Bold';    BoldTextStyle.Font.Bold := True;    BoldTextStyle.SetElements := BoldTextStyle.SetElements + [spbfFontBold];     // Add our own style for centered paragraphs    CenterStyle := Document.AddStyle();    CenterStyle.Kind := vskTextBody; // This style will be applied to the whole Paragraph    CenterStyle.Name := 'Table Body Centered';    CenterStyle.Font.Name := 'Verdana';    CenterStyle.Font.Size := 8;    CenterStyle.Alignment := vsaCenter;    CenterStyle.MarginTop := 2 * ONE_POINT_IN_MM;    CenterStyle.MarginBottom := 2 * ONE_POINT_IN_MM;    CenterStyle.SetElements :=      [spbfFontSize, spbfFontName, spbfAlignment, sseMarginTop, sseMarginBottom];     // Create the Document, and add a simple Heading    Page := Document.AddTextPageSequence;    Paragraph := Page.AddParagraph;    Paragraph.Style := Document.StyleHeading1;    Paragraph.AddText('Simple Table');      // Add our Table, which will have 5 columns    Table := Page.AddTable;    Table.PreferredWidth := Dimension(100, dimPercent);     // As we will be merging cells, we have to define all the column widths    // so that ODT knows how many columns there will be.    // Getting the width exactly correct is not essential as LibreOffice Writer    // and Microsoft Word each treat this as a PreferredWidth value.    Table.ColWidthsUnits:=dimMillimeter;     Table.AddColWidth(20);    Table.AddColWidth(50);    Table.AddColWidth(50);    Table.AddColWidth(50);    Table.AddColWidth(100);     // Add a single row at the start which will contain merged cells    Row := Table.AddRow;    Row.BackgroundColor := RGBToFPColor(192, 192, 192); // Grey Shading    Row.Header := True; // Tell the table this is a Header Row                        // Header Rows repeat at the top of each page     Cell := Row.AddCell;    Cell.SpannedCols:=1;    Paragraph := Cell.AddParagraph;    Paragraph.Style := CenterStyle;    Paragraph.AddText('Category 1').Style := BoldTextStyle;     Cell := Row.AddCell;    Cell.SpannedCols:=2;  // Make this cell cover two columns    Paragraph := Cell.AddParagraph;    Paragraph.Style := CenterStyle;    Paragraph.AddText('Category 2').Style := BoldTextStyle;     Cell := Row.AddCell;    //Cell.Row.;    Cell.SpannedCols:=2;  // Make this cell cover two columns    Paragraph := Cell.AddParagraph;    Paragraph.Style := CenterStyle;    Paragraph.AddText('Category 3').Style := BoldTextStyle;     // Add 21 rows to the Table, with the first being the header row    for iRow := 0 to 20 do    begin      Row := Table.AddRow;       // Header Row      if iRow = 0 then      begin        Row.BackgroundColor := RGBToFPColor(192, 192, 192); // Grey Shading        Row.Header := True; // Tell the table this is a Header Row                            // Header Rows repeat at the top of each page      end;       // Add 5 cells to each Row      for iCol := 0 to 4 do      begin        Cell := Row.AddCell;         // Each Cell is a TvRichText, we cad add anything we can add to the main        // body of a Document (for now Paragraphs, Tables or Lists)        Paragraph := Cell.AddParagraph;        Paragraph.Style := CenterStyle;         if iRow = 0 then          Paragraph.AddText(Format('Header Col %d', [iCol])).Style := BoldTextStyle        else          Paragraph.AddText(Format('Cell %d x %d', [iRow, iCol]));      end;    end;      Document.WriteToFile('123.docx', vfDOCX);    Document.WriteToFile('123.odt', vfODT);  finally    Document.Free;  end; end; end.  

jianwt:
@KodeZwerg Thanks!
@wp  The code works, but don't know how to draw 2 horizontal lines.

Navigation

[0] Message Index

[#] Next page

Go to full version