I can load a dxf file to a tsgimage and show on my
delphi form,but how to
add a text string on this tsgimage ,
then print this tsgimage to printer?
How to add text on sgimage?
Moderators: SDS, support, admin
Hello,
The following example is based on two demo applications from the <b>CADImportVCL</b> package (available on: http://www.cadsofttools.com/download/cadimportvcl.zip): <b>Add New Entities</b> and <b>Viewer</b>.
Sergey.
please post questions to the forum or write to support@cadsofttools.com
The following example is based on two demo applications from the <b>CADImportVCL</b> package (available on: http://www.cadsofttools.com/download/cadimportvcl.zip): <b>Add New Entities</b> and <b>Viewer</b>.
Code: Select all
<b>procedure</b> TForm1.CADImport2761Click(Sender: TObject);
<b>const</b> PO: <b>array</b>[Boolean] <b>of</b> TPrinterOrientation = (poPortrait,poLandscape);
<b>var</b>
W,H: Double;
PW,PH: Integer;
Ent: TsgDXFText;
Img: TsgDXFImage;
FStoredNullWidth: Integer;
<b>begin</b>
{The following section is based on <b>Add New Entities</b> demo: ..\cadimportvcl\Delphi\Demos\Add new entities\.. }
sgImage1.LoadFromFile('C:\Test.dxf');
Img := TsgDXFImage(sgImage1.Picture.Graphic);
sgImage1.Align := alClient;
Ent := TsgDXFText.Create;
Ent.Point := Img.Extents.TopLeft;
Ent.Text := 'This is a test! This text has been added to a DXF file.';
Ent.HAlign := 2;
Ent.VAlign := 2;
Ent.Height := 50;
Img.Converter.Sections[csEntities].AddEntity(Ent);
<b>if</b> Assigned(Img.Converter.OnCreate) <b>then</b>
Img.Converter.OnCreate(Ent);
Img.Converter.Loads(Ent);
Img.GetExtents;
{The following section is based on <b>Viewer</b> demo: ..\cadimportvcl\Delphi\Demos\Viewer\.. }
<b>with</b> sgImage1.Picture <b>do</b>
Printer.Orientation := PO[Width > Height];
<b>if</b> PrintDialog1.Execute <b>then
begin</b>
FStoredNullWidth := Img.NullWidth;
Img.NullWidth := 3;
<b>with</b> Printer, sgImage1.Picture <b>do
begin</b>
W := PageWidth / Width;
H := PageHeight / Height;
<b>if</b> W > H <b>then</b> W := H;
PW := Round(W * Width);
PH := Round(W * Height);
BeginDoc;
Canvas.StretchDraw(Bounds((PageWidth-PW) div 2, (PageHeight-PH) div 2, PW, PH), Graphic);
EndDoc;
<b>end</b>;
Img.NullWidth := FStoredNullWidth;
sgImage1.Repaint;
<b>end</b>;
<b>end</b>;
please post questions to the forum or write to support@cadsofttools.com
Hi Sergey:
How can I define the font type SHX, in a entity TsgDXFText?.
sgImage1.LoadFromFile('C:\Test.dxf');
Img := TsgDXFImage(sgImage1.Picture.Graphic);
sgImage1.Align := alClient;
Ent := TsgDXFText.Create;
Ent.Point := Img.Extents.TopLeft;
Ent.Text := 'This is a test! This text has been added to a DXF file.';
Ent.HAlign := 2;
Ent.VAlign := 2;
Ent.Height := 50;
<font color="red"> <b>Ent.SHXFont := <-----------------READONLY PROPERTY </b></font id="red">
Thank You,
Roberto
How can I define the font type SHX, in a entity TsgDXFText?.
sgImage1.LoadFromFile('C:\Test.dxf');
Img := TsgDXFImage(sgImage1.Picture.Graphic);
sgImage1.Align := alClient;
Ent := TsgDXFText.Create;
Ent.Point := Img.Extents.TopLeft;
Ent.Text := 'This is a test! This text has been added to a DXF file.';
Ent.HAlign := 2;
Ent.VAlign := 2;
Ent.Height := 50;
<font color="red"> <b>Ent.SHXFont := <-----------------READONLY PROPERTY </b></font id="red">
Thank You,
Roberto
Hi Roberto,
It is necessary to use <b>TsgDXFStyle</b> entity when changing font name for the <b>TsgDXFText</b> entity. Please use the following code:
Sergey.
please post questions to the forum or write to support@cadsofttools.com
It is necessary to use <b>TsgDXFStyle</b> entity when changing font name for the <b>TsgDXFText</b> entity. Please use the following code:
Code: Select all
<b>procedure</b> TMyApp.Forum_276_Click(Sender: TObject);
<b>var</b>
Ent: TsgDXFText;
Img: TsgDXFImage;
vTextStyle: TsgDXFStyle;
<b>begin</b>
bUseSHXFonts := True;
sgImage1.LoadFromFile('c:\test.dxf');
Img := TsgDXFImage(sgImage1.Picture.Graphic);
sgImage1.Align := alClient;
vTextStyle := TsgDXFStyle.Create;
vTextStyle.Name := 'styleGothice';
vTextStyle.PrimaryFont := 'gothice.shx';
Img.Converter.Loads(vTextStyle);
Ent := TsgDXFText.Create;
Ent.Point := Img.Extents.TopLeft;
Ent.Text := 'This is a test! This text was added to a DXF file. Gothice.shx is used.';
Ent.HAlign := 2;
Ent.VAlign := 2;
Ent.Height := 50;
Ent.Style := vTextStyle;
Img.Converter.Sections[csStyles].AddEntity(vTextStyle);
Img.Converter.Sections[csEntities].AddEntity(Ent);
if Assigned(Img.Converter.OnCreate) then
Img.Converter.OnCreate(Ent);
Img.Converter.Loads(Ent);
Img.GetExtents;
<b>end</b>;
please post questions to the forum or write to support@cadsofttools.com