How to .SHX fonts

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
aby
Posts: 81
Joined: 21 May 2007, 13:02
Location: Turkey

How to .SHX fonts

Post by aby » 04 May 2011, 17:48

Hi,


Entity->Style = CadMngr->CurrDimStyle;
Entity->Style->TextStyle->FontName = "SIMPLEX";
Entity->Style->TextStyle->PrimaryFont = "C:\\BILSAR\\SIMPLEX.SHX";


The code snippet above is trying to use SIMPLEX text style with no success.

BILSAR directory contains the simplex. shx file.
When I examine with the debugger PrimayFont is exactly like the above.
What am I missing or could you provide an example on how to use simplex.shx fonts.

Thanks

aby

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to .SHX fonts

Post by support » 05 May 2011, 12:54

Hello aby.
The code you posted changes the text style for a dimension object. However it's not enough to affect visualization. All entities that use the modified style must be loaded to converter. For example try to change dimension text visualization with the simply AutoCAD file (attached). It contains one dimension entity only. Loading the dimension from entities section and MText from dimension's block required to change dimension text visualization:

Code: Select all

  TsgDXFDimension* dim = (TsgDXFDimension*)FImg->Converter->Entities[0];
  FImg->Converter->Loads(dim);

  TsgDXFGroup* group = (TsgDXFGroup*)FImg->Converter->Sections[csEntities];
  FImg->Converter->Loads(((TsgDXFBlock*)group->Entities[3])->Entities[6]);

  //if not doublebuffered. Otherwise FImg->GetExtents();
  sgPaintBox->Invalidate();

Please note, dimension inner entities contained in blocks section.

Of course SHX fonts must be switched on in your application.

Alexander.
Attachments
dimension.zip
(7.78 KiB) Downloaded 2749 times
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

aby
Posts: 81
Joined: 21 May 2007, 13:02
Location: Turkey

Re: How to .SHX fonts

Post by aby » 05 May 2011, 17:52

Alexander.

I've downloaded your dwg and try to do your posting . I need some clarifications.

TsgDXFDimension* dim = (TsgDXFDimension*)FImg->Converter->Entities[0];
FImg->Converter->Loads(dim);

1) From above I understand Entites[0] is aTsgDXFDimension object. ( True or false)

TsgDXFGroup* group = (TsgDXFGroup*)FImg->Converter->Sections[csEntities];
FImg->Converter->Loads(((TsgDXFBlock*)group->Entities[3])->Entities[6]);

2) What is group csEntities ? What is Group and Why Entities[3] && Entities[6];
What are they referring?

Please could you post a working example on how to change to a simplex fonts. It can be on Delphi it doesnt matter.

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to .SHX fonts

Post by support » 06 May 2011, 10:49

Hello aby.
You're correct, Entites[0] is a TsgDXFDimension object. The attached file contains one entity (dimension) only, so there is only one entity in Converter->Entities list. However DWG/DXF structure provides a dimension consists of a set of other entities such as lines, solids, MText. These entities can be accessed via BLOCKS section FImg->Converter->Sections[csBlocks]. My previous post contains an error, sorry. Group must be refer to BLOCKS, not ENTITIES:

Code: Select all

  TsgDXFDimension* dim = (TsgDXFDimension*)FImg->Converter->Entities[0];
  FImg->Converter->Loads(dim);

  //      FImg->Converter->Sections[csEntities] ---- incorrect
  TsgDXFGroup* group = (TsgDXFGroup*)FImg->Converter->Sections[csBlocks];
  FImg->Converter->Loads(((TsgDXFBlock*)group->Entities[3])->Entities[6]);

  //if not doublebuffered. Otherwise FImg->GetExtents();
  sgPaintBox->Invalidate();
Dimension's block have index 3 and the MText have index 6 within block's entities.

MText can be also accessed as TsgDXFDimension->Block->Entities:

Code: Select all

  TsgDXFDimension* dim = (TsgDXFDimension*)FImg->Converter->Entities[0];
  FImg->Converter->Loads(dim);

  FImg->Converter->Loads(dim->Block->Entities[6]);

  //if not doublebuffered. Otherwise FImg->GetExtents();
  sgPaintBox->Invalidate();
Any of above posted snippets must be run after your code changing the text style. More complex files with multiple dimensions/texts require reload all entities that use the modified style.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

aby
Posts: 81
Joined: 21 May 2007, 13:02
Location: Turkey

Re: How to .SHX fonts

Post by aby » 06 May 2011, 11:45

Alexander,

Thanks for your clarifying post.

First I'm not using MText. Simply I'm using Text.
FImg->Converter->Loads(((TsgDXFBlock*)group->Entities[3])->Entities[6]);
So we don't need this line. It is giving an error if it is included.

The bad news is the issue is party been solved. It is continuing to display the default in Arial fonts.
The good news is If saved to a file and opened on AutoCad it is displaying as required.

Good luck,
Aby

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to .SHX fonts

Post by support » 06 May 2011, 12:37

Hello aby.
The code was provided for the attached file. This file visualization must be changed correctly. Please specify that have you meant by "issue is partially been solved". Have you received the visualization with SHX fonts for the attached file?
For any other drawing all entities using the modified style must be reloaded. Save/load file will reload all parameters. However it can be useful if only export library owned.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to .SHX fonts

Post by support » 06 May 2011, 14:19

Hello aby.
The following code can be used to change text style for an entity then reload all affected entities:

Code: Select all

var
  dim: TsgDXFDimension;
  block: TsgDXFBlock;
  I: integer;
begin
  dim := TsgDXFDimension(Img.Converter.entities[some_index]);
  dim.Style.TextStyle.FontName := 'SIMPLEX';
  dim.Style.TextStyle.PrimaryFont := 'SIMPLEX.SHX';

  for I := 0 to Img.Converter.Sections[csBlocks].Count - 1 do
  begin
    block := TsgDXFBlock(Img.Converter.Sections[csBlocks].Entities[I]);
    ChangeStyle(block)
  end;

  ChangeStyle(Img.Converter.Sections[csEntities]);

  Img.GetExtents();
end;

procedure TForm1.ChangeStyle(group: TsgDXFGroup);
var
  I: integer;
  ent: TsgDXFEntity;
begin
  for I := 0 to group.Count - 1 do
  begin
    ent := TsgDXFEntity(group.Entities[I]);

    if (ent.EntType = ceDimension) or (ent.EntType = ceMText) or (ent.EntType = ceText) or (ent.EntType = ceAttrib) or (ent.EntType = ceAttdef) then
      Img.Converter.Loads(ent);

    if (ent.EntType = ceInsert) then
      ChangeStyle(TsgDXFGroup(ent));

  end;
end; 
I attach the file to test the snippet.

Alexander.
Attachments
styles.zip
(12.63 KiB) Downloaded 3921 times
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply