Lisp .... textfontstyle bold, italic, bolditlaic

I am not able to set a textstyle to Bold, Italic, or BoldItalic. Everything else seems to be working as expected. Any ideas?

(defun HASD:MakeTextStyle ( sName / )

(setq myTextStyles (vla-get-textstyles thisdrawing))
        (setq myTextStyle (vla-add myTextStyles sName))

   (setq sFontFile "Times New Roman")
  (vla-put-fontfile myTextStyle sFontFile)
  (vla-put-textfontstyle myTextStyle 2)
  (vla-put-height myTextStyle 0)
  (vla-put-width myTextStyle 1.0)
  (vla-put-obliqueangle myTextStyle (HASD:D2R 0))

)

Comments

  • vla-put-textfontstyle isn't an available property. To set bold, italic etc.. I believe you have to set the style to the specific font file within the desired font familly

    e.g.

    (vla-put-fontfile myTextStyle "times.ttf")  for Times New Roman Regular
    (vla-put-fontfile myTextStyle "timesbi.ttf") for Times New Roman Bold Italic

    With TTF it's not a good idea to apply width factors, or obliquing angles. Potentially this will impact on performance (does in AutoCAD). These settings should be limited to native SHX fonts, which they are intended for.

    Regards,
    Jason Bourhill

  • vla-put-textfontstyle isn't an available property. To set bold, italic etc.. I believe you have to set the style to the specific font file within the desired font familly

    e.g.

    (vla-put-fontfile myTextStyle "times.ttf")  for Times New Roman Regular
    (vla-put-fontfile myTextStyle "timesbi.ttf") for Times New Roman Bold Italic

    With TTF it's not a good idea to apply width factors, or obliquing angles. Potentially this will impact on performance (does in AutoCAD). These settings should be limited to native SHX fonts, which they are intended for.

    Regards,
    Jason Bourhill


    Thanks. I've removed the oblique angle and width code as suggested. Its working except for bold. BricsCAD is displaying the style as Timesb.ttf.shx and Arial.ttf.shx in drawing explorer. Regular, BoldItalic, and Italic look correct.
  • I would check that you are calling the correct TTF filename. Times Roman Bold is "timesbd.ttf" not "timesb.ttf"

    Regards,
    Jason Bourhill
  • To add more detail with vla-put-fontfile, BricsCAD doesn't seem to correctly validate whether the font file exists, it will actually accept any valid string
    (vla-put-fontfile myTextStyle "foofont"). If the font isn't found, then BricsCAD assumes it must be an shx and appends this extension e.g. "foofont.shx", it doesn't then check that this file exists. This approach is probably fine, as BricsCAD will default to using FONTALT for the missing font.

    Perhaps add a check to vla-put-fontfile?

    [code]; Will check whether the given font exists or not
    ; returns the font if it exists
    ; returns the font set by FONTALT if it doesn't
    (defun checkfont (fontfile / winfonts)
        (setq winfonts "C:\\Windows\\Fonts\\")
        (if
            (or (findfile fontfile)(findfile (strcat winfonts fontfile)))
                fontfile
                (getvar 'FONTALT)
        )
    )
    [/code]

    [code](vla-put-fontfile myTextStyle (checkfont "foofont.ttf"))[/code]


    Regards,
    Jason Bourhill

  • Thanks

    To add more detail with vla-put-fontfile, BricsCAD doesn't seem to correctly validate whether the font file exists, it will actually accept any valid string
    (vla-put-fontfile myTextStyle "foofont"). If the font isn't found, then BricsCAD assumes it must be an shx and appends this extension e.g. "foofont.shx", it doesn't then check that this file exists. This approach is probably fine, as BricsCAD will default to using FONTALT for the missing font.

    Perhaps add a check to vla-put-fontfile?

    ; Will check whether the given font exists or not; returns the font if it exists; returns the font set by FONTALT if it doesn't(defun checkfont (fontfile / winfonts)    (setq winfonts "C:\\Windows\\Fonts\\")    (if        (or (findfile fontfile)(findfile (strcat winfonts fontfile)))            fontfile            (getvar 'FONTALT)    ))    


    (vla-put-fontfile myTextStyle (checkfont "foofont.ttf"))  



    Regards,
    Jason Bourhill

This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. Click one of the buttons on the top bar to get involved!