Recent

Author Topic: The problem of drawing lines(fpvectorial)  (Read 2845 times)

jianwt

  • Jr. Member
  • **
  • Posts: 85
The problem of drawing lines(fpvectorial)
« on: January 26, 2023, 10:58:32 am »
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.)

« Last Edit: January 26, 2023, 12:12:03 pm by jianwt »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: The problem of drawing lines(fpvector)
« Reply #1 on: January 26, 2023, 11:25:15 am »
When I run your code I don't see the issue. Please post code so that I can reproduce and work on it.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: The problem of drawing lines(fpvector)
« Reply #2 on: January 26, 2023, 11:46:41 am »
I'm a beginner and I want to ask a question.
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.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jianwt

  • Jr. Member
  • **
  • Posts: 85
Re: The problem of drawing lines(fpvectorial)
« Reply #3 on: January 26, 2023, 12:17:21 pm »
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  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  10.   fpvectorialpkg,
  11.   fpvectorial,
  12.   fpvutils   // For RGBToFPColor()
  13.   ;
  14.  
  15. type
  16.  //type
  17.   { TvTableHelper }
  18.   TvTableHelper = class helper for TvTable
  19.   public
  20.     function AddColWidth(AValue: Double): Integer;
  21.   end;
  22.  
  23.   { TForm1 }
  24.  
  25.   TForm1 = class(TForm)
  26.     Button1: TButton;
  27.     procedure Button1Click(Sender: TObject);
  28.   private
  29.  
  30.   public
  31.  
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41.  
  42.  
  43. { TvTableHelper }
  44.  
  45. function TvTableHelper.AddColWidth(AValue: Double): Integer;
  46. begin
  47.   SetLength(ColWidths, Length(ColWidths) + 1);
  48.   ColWidths[High(ColWidths)] := AValue;
  49.   Result := 0;
  50. end;
  51.  
  52. { TForm1 }
  53. procedure TForm1.Button1Click(Sender: TObject);
  54. var
  55.   Document: TvVectorialDocument;
  56.   Page: TvTextPageSequence;
  57.   Paragraph: TvParagraph;
  58.   BoldTextStyle: TvStyle;
  59.   CenterStyle: TvStyle;
  60.   Table: TvTable;
  61.   Row: TvTableRow;
  62.  // Col:TvTablecol;
  63.   Cell: TvTableCell;
  64.   iRow: Integer;
  65.   iCol: Integer;
  66.  
  67. const
  68.   // Most dimensions in FPVectorial are in mm.  If you want to specify
  69.   // anything in other units, be ready to do the conversion...
  70.   ONE_POINT_IN_MM = 0.35278;
  71.  
  72. begin
  73.   Document := TvVectorialDocument.Create;
  74.   try
  75.     //  Adds the defaut Paragraph Styles
  76.     //    StyleTextBody, StyleHeading1,
  77.     //    StyleHeading2 & StyleHeading3
  78.     Document.AddStandardTextDocumentStyles(vfUnknown);
  79.  
  80.     // Add our own Style for bolded text elements
  81.     BoldTextStyle := Document.AddStyle();
  82.     BoldTextStyle.Kind := vskTextSpan; // This style will only be applied to selected Text Spans
  83.     BoldTextStyle.Name := 'Bold';
  84.     BoldTextStyle.Font.Bold := True;
  85.     BoldTextStyle.SetElements := BoldTextStyle.SetElements + [spbfFontBold];
  86.  
  87.     // Add our own style for centered paragraphs
  88.     CenterStyle := Document.AddStyle();
  89.     CenterStyle.Kind := vskTextBody; // This style will be applied to the whole Paragraph
  90.     CenterStyle.Name := 'Table Body Centered';
  91.     CenterStyle.Font.Name := 'Verdana';
  92.     CenterStyle.Font.Size := 8;
  93.     CenterStyle.Alignment := vsaCenter;
  94.     CenterStyle.MarginTop := 2 * ONE_POINT_IN_MM;
  95.     CenterStyle.MarginBottom := 2 * ONE_POINT_IN_MM;
  96.     CenterStyle.SetElements :=
  97.       [spbfFontSize, spbfFontName, spbfAlignment, sseMarginTop, sseMarginBottom];
  98.  
  99.     // Create the Document, and add a simple Heading
  100.     Page := Document.AddTextPageSequence;
  101.     Paragraph := Page.AddParagraph;
  102.     Paragraph.Style := Document.StyleHeading1;
  103.     Paragraph.AddText('Simple Table');
  104.  
  105.  
  106.     // Add our Table, which will have 5 columns
  107.     Table := Page.AddTable;
  108.     Table.PreferredWidth := Dimension(100, dimPercent);
  109.  
  110.     // As we will be merging cells, we have to define all the column widths
  111.     // so that ODT knows how many columns there will be.
  112.     // Getting the width exactly correct is not essential as LibreOffice Writer
  113.     // and Microsoft Word each treat this as a PreferredWidth value.
  114.     Table.ColWidthsUnits:=dimMillimeter;
  115.  
  116.     Table.AddColWidth(20);
  117.     Table.AddColWidth(50);
  118.     Table.AddColWidth(50);
  119.     Table.AddColWidth(50);
  120.     Table.AddColWidth(100);
  121.  
  122.     // Add a single row at the start which will contain merged cells
  123.     Row := Table.AddRow;
  124.     Row.BackgroundColor := RGBToFPColor(192, 192, 192); // Grey Shading
  125.     Row.Header := True; // Tell the table this is a Header Row
  126.                         // Header Rows repeat at the top of each page
  127.  
  128.     Cell := Row.AddCell;
  129.     Cell.SpannedCols:=1;
  130.     Paragraph := Cell.AddParagraph;
  131.     Paragraph.Style := CenterStyle;
  132.     Paragraph.AddText('Category 1').Style := BoldTextStyle;
  133.  
  134.     Cell := Row.AddCell;
  135.     Cell.SpannedCols:=2;  // Make this cell cover two columns
  136.     Paragraph := Cell.AddParagraph;
  137.     Paragraph.Style := CenterStyle;
  138.     Paragraph.AddText('Category 2').Style := BoldTextStyle;
  139.  
  140.     Cell := Row.AddCell;
  141.     //Cell.Row.;
  142.     Cell.SpannedCols:=2;  // Make this cell cover two columns
  143.     Paragraph := Cell.AddParagraph;
  144.     Paragraph.Style := CenterStyle;
  145.     Paragraph.AddText('Category 3').Style := BoldTextStyle;
  146.  
  147.     // Add 21 rows to the Table, with the first being the header row
  148.     for iRow := 0 to 20 do
  149.     begin
  150.       Row := Table.AddRow;
  151.  
  152.       // Header Row
  153.       if iRow = 0 then
  154.       begin
  155.         Row.BackgroundColor := RGBToFPColor(192, 192, 192); // Grey Shading
  156.         Row.Header := True; // Tell the table this is a Header Row
  157.                             // Header Rows repeat at the top of each page
  158.       end;
  159.  
  160.       // Add 5 cells to each Row
  161.       for iCol := 0 to 4 do
  162.       begin
  163.         Cell := Row.AddCell;
  164.  
  165.         // Each Cell is a TvRichText, we cad add anything we can add to the main
  166.         // body of a Document (for now Paragraphs, Tables or Lists)
  167.         Paragraph := Cell.AddParagraph;
  168.         Paragraph.Style := CenterStyle;
  169.  
  170.         if iRow = 0 then
  171.           Paragraph.AddText(Format('Header Col %d', [iCol])).Style := BoldTextStyle
  172.         else
  173.           Paragraph.AddText(Format('Cell %d x %d', [iRow, iCol]));
  174.       end;
  175.     end;
  176.  
  177.  
  178.     Document.WriteToFile('123.docx', vfDOCX);
  179.     Document.WriteToFile('123.odt', vfODT);
  180.   finally
  181.     Document.Free;
  182.   end;
  183.  
  184. end;
  185.  
  186. end.
  187.  
  188.  

jianwt

  • Jr. Member
  • **
  • Posts: 85
Re: The problem of drawing lines(fpvectorial)
« Reply #4 on: January 26, 2023, 12:31:35 pm »
@KodeZwerg Thanks!
@wp  The code works, but don't know how to draw 2 horizontal lines.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: The problem of drawing lines(fpvectorial)
« Reply #5 on: January 26, 2023, 01:21:01 pm »
OK, now I understand your question. But AFAICS, it seems that the text format writers to not allow to have drawing commands in a page. I am not the author of fpvectorial (just taking care of some adjustments) and cannot evaluate at the moment whether this is a serious limitation or not.

Please give me some time to investigate the issue.

jianwt

  • Jr. Member
  • **
  • Posts: 85
Re: The problem of drawing lines(fpvectorial)
« Reply #6 on: January 29, 2023, 02:15:17 pm »
 @wp   Can  draw 2 line segments in docx document in advance and set the parameter names that can be replaced, such as: "[Parameter 1]", then open the docx document in fpvectorial, and replace the "[parameter 1]" with the character you need to add, and then save again, this idea fpvectorial can do?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: The problem of drawing lines(fpvectorial)
« Reply #7 on: January 29, 2023, 03:40:23 pm »
fpVectorial supports two types of pages: a graphical page in which lines, graphics shapes and text can be placed arbitrarily (TvVectorialPage), and a textual page for paragraphs, tables etc, more typical of word processing (TvTextPageSequence). I don't know whether it is possible to draw an arbitrary line in a textual page - well, maybe in fpVectorial, but the main question is what Word will be doing with such a document.

I could imagine that it is possible to extend the TvParagraph such that it allows to draw a horizontal line below the paragraph across the page. In the next step it would be required to find the location and the format in the docx and odt files so that the writer will be able to store this information correctly. All this requires some work... I am not intending to spend this time at the moment. But maybe somebody submits a patch which I'd be happy to commit.

jianwt

  • Jr. Member
  • **
  • Posts: 85
Re: The problem of drawing lines(fpvectorial)
« Reply #8 on: January 30, 2023, 01:20:42 am »
 @wp  Some documents of need to be in line format. Please see the screenshot or the attached document. I hope you can enjoy the service provided by fpvectorial. Thank you for your help! Wish you a happy life!!
« Last Edit: January 30, 2023, 10:45:45 am by jianwt »

 

TinyPortal © 2005-2018