Page 1 of 1

How to .SHX fonts

Posted: 04 May 2011, 17:48
by aby
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

Re: How to .SHX fonts

Posted: 05 May 2011, 12:54
by support
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.

Re: How to .SHX fonts

Posted: 05 May 2011, 17:52
by aby
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.

Re: How to .SHX fonts

Posted: 06 May 2011, 10:49
by support
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.

Re: How to .SHX fonts

Posted: 06 May 2011, 11:45
by aby
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

Re: How to .SHX fonts

Posted: 06 May 2011, 12:37
by support
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.

Re: How to .SHX fonts

Posted: 06 May 2011, 14:19
by support
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.