The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.
#82520 by lmiddendorf
Sat Oct 14, 2023 1:24 pm
Hello!!

I am new to DCAL, but not to programming.
My current font (as usual) is Arial.ttf.
I am using the "getcurrfont" in a macro and it is coming in as Arial.shx.
Let me tell you what I have tried:
--Tools-->Program Preferences-->Misc-->defaults: SHX set to "TXT" and True Type set to "Arial".
--I deleted all Arial.shx from the fonts folder.
--Using printstr to ensure "getcurrfont" is Arial.

Any help in this matter is greatly appreciated.
#82521 by dhs
Sat Oct 14, 2023 3:21 pm
Hello lmiddendorf.

I am not getting the same result as you when I test the getcurrfont procedure in a DCAL macro.
The DCAL manual states that the procedure returns a "string of up to eight characters that represents the font file without path or extension". The "eight characters" specified is obviously no longer applicable as I am seeing the full font name for longer fonts, but what I am seeing returned is in fact the font name without path or extension.
Not sure why I am getting a different result? I tested in DataCAD 22, and the source of my test macro is shown below. Can you supply any further information about your setup?

Code: Select allPROGRAM TestFont;

VAR
   str : str255;

BEGIN
   wrtlvl ('Font Test');
   lblsinit;
   lblson;
   getcurrfont (str);
   printstr (str, 1,1,1,0,false);
END TestFont.


Out of interest I also looked at the font name returned in a DCAL for Delphi macro. The getcurrfont procedure is not available there, so instead I looked at PGSavevar^.fontname which also returned the name of the font only (no path or extension).
#82522 by lmiddendorf
Sat Oct 14, 2023 3:58 pm
Thank you for the timely reply.

As I read your reply and re-read my post, I was a little vague. The printstr is saying "Arial" on the screen, but in the following edited code the word "TEST" (after an Identify) says "Arial.shx" not "Arial.ttf".

ent_init (ent, enttxt);
textloc.x := hpnt1.x + ((olap * 1.125) * newcose);
textloc.y := hpnt1.y + ((olap *1.125) * newsine);
newloc.x := textloc.x + ((dy/2.0) * newsine);
newloc.y := textloc.y - ((dy/2.0) * newcose);
ent.txtpnt := newloc;
ent.txtang := newang;
ent.txtsize := txtsize;
ent.txtslant := txtslant;
ent.txtaspect :=txtaspect;
ent.txtbase := 0.0;
ent.txthite := 0.0;
getcurrfont (setfont);
ent.txtfont := setfont;
txtaline := 0;
ent.txtstr := "TEST";
linecolor := tcolor;
txtweight := tweight;
ent_add (ent);
ent_draw (ent, drmode_white);

I know there are a lot of variables here. This block comes from the "TXTLINE" macro found on the "open source" part of your website. I am trying to adapt it for my brother if that is OK.
#82523 by dhs
Sat Oct 14, 2023 10:51 pm
Unfortunately I think you have come across a limitation of DCAL. I suspect that getcurrfont will always assume that you are specifying an SHX font (since it has a parameter of only the font name with no indication of SHX or TTF). DataCAD did not support TTF fonts at the time DCAL was developed, and there have only been limited updates since that time. You could try doing an ent_update for the font after creating the entity (actually worth a try, but I don't really expect it will make any difference).

DCAL for Delphi specifies a field in the enttxt record to indicate if it is a Windows (TTF) font. Although the field is not exposed in Classic DCAL, it should be possible to define a variant record (that overlaps the enttxt record with a structure that contains the desired flag at the appropriate offset) to allow you to modify the appropriate byte in the entity record.
The record layout as defined in DCAL for Delphi is below:
Code: Select all         entTxt:
            (txtpnt: point; { Point around where text will be justified }
               txtpnt2: point; { Second Point for fit/aligned text }
               txttype: RTextType;
               txtsiz: aFloat;
               txtang: aFloat;
               txtslant: aFloat;
               txtaspect: aFloat; { aspect ratio }
               txtBase: aFloat;
               txtHite: aFloat;
               txtfon: fontstr;
               txtdisplayttf: TDisplayTTF;
               TxtWinfont: TFontType;
               fontNum: aSInt;
               txtunderline, txtoverline: boolean;
               txtstr: str255); { set in dcdata }

TxtWinFont is the field you will need to modify. TFontType is an enumerated type with only 2 values (font_shx, font_ttf). If you are familiar with programming then you can probably work out how to do this.
#82526 by dhs
Sun Oct 15, 2023 2:23 pm
Hi Lynn,

You will need Delphi (from Embarcadero) to use DCAL for Delphi. I qualify for the free Community Edition which provides all the required functionality (basically eligibility for CE depends on revenue being less than $5k). If you have an older version of Delphi then I believe anything from Delphi 5 upwards is suitable.

You will find a comparison of Classic and Delphi versions of DCAL at https://dhsoftware.com.au/dcalcompare.htm

There is also a version of DCAL for C++ if you are more comfortable with that then with Delphi Pascal. I have never used it but I believe it has the same capabilities as the Delphi version.

Regards,
David
#82538 by dhs
Mon Oct 23, 2023 2:51 pm
Had a bit of spare time on the train last night, so decided to look into this a bit further ....

I did a dump of a few text entities to locate the fields related to TTF/SHX fonts. I thought I would find the fields that were declared in the D4D record (txtdisplayttf, TxtWinfont), but it was not exactly as I expected. There were 2 significant bytes in the record that differed between the SHX and TTF entities:
A hex dump of the relevant part of the entities is shown below
TxtEntDumps.png

As you can see bytes at offsets of #185 and #186 (389 and 390) are different. I expected to see txtdisplayttf information in the record immediately before TxtWinFont but it was not as expected.
The txtdisplayttf field has the following structure:
Code: Select all   TDisplayTTF = packed record
      dooutline: boolean;
      dofill: boolean;
      OutlineClr: aSInt; { Range 1..255 }
      FillClr: integer; { Range 1..255, Add 1000 Offset to fixed RGB }
   end;

I tried looking at TTF text entities with different outline and fill properties, but the entity dump did not change. What I did find was that in addition to the fields in the entity record there are also attributes used to define the font:
SHX entities had an attribute named Text.ShxFontName.
TTF entities had 2 attributes named Text.WFFontName and Text.TTFProp

Although I have not tested, it would probably be possible to create a TTF Font entity using Classic DCAL by modifying the bytes at offsets 389 and 390 and adding the Text.WFFontName and Text.TTFProp attributes (and removing the Text.ShxFontName attribute) - this would probably need to be done after creating the SHX entity (i.e create the SHX ent and then modify it to change to desired TTF).

The code that I wrote to examine the entities is shown below (similar variant record could be used to modify the appropriate bytes of the entity record). I do not hold this up as an example of good programming (there is little error checking)!
Code: Select allPROGRAM TestFont;

TYPE
   EntOverlay = RECORD
     i : integer;
     CASE integer OF
      0 : (e : entity);
      1 : (o : array [0..833] of byte);  {I exstablished this as the size of the entity record using the sizeof function }
   END;

VAR
   entrec : EntOverlay;
   res, key : integer;
   mode : mode_type;
   addr : entaddr;
   i, j : integer;
   ch : char;
   fl : file;

BEGIN
   selecttype := 1;  {entity}
   if getmode ('analyse as text entity', mode, key) = res_normal then
      addr := ent_first (mode);
      if ent_get (entrec.e, addr) then
         i := f_create (fl, 'TextEnt.txt', true);
         for i := 0 to 833 do
            j := f_wrchar (fl, entrec.o[i]);
         end;
         i := f_close(fl);
         wrterr ('TextEnt.txt file has hopefully been written');
      else
         wrterr ('Unable to read entity (Macro exits)');
      end;
   else
      wrterr ('No entity selected (Macro exits)');
   end;
   
END TestFont.[code][/code]


Note that to find attributes you can use the AttributeMgr macro available for download on my web site (although it is not a lot of help in displaying the value of attributes that are not text (even 'text' attributes can contain non-textual information - this is the case for the Text.TTFProp attribute mentioned above)

Who is online

Users browsing this forum: No registered users and 43 guests

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.

DataCAD

Software for Architects Since 1984