Author Topic: changing font of text style at startup  (Read 6794 times)

0 Members and 1 Guest are viewing this topic.

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #15 on: November 05, 2017, 05:25:11 PM »
OK, so i think that my problem is the font i am trying to use, SimSun, is peculiar, it is a ttc rather than a ttf or shx.  I added to CAB's code with a different "put wrap" (i am making up terminology because I know very little) from Fixo on a similar problem, and I changed the input font to simplex_.ttf to test.  I also tried to use simsun.ttc, and it did replace the font in the styles, but it did not recognize the "SimSun" font I would be able to manually select if I went through all my different styles in all our different template drawings.  Instead it gave me the attached jpg.

Here is the code I am currently working with:
Code: [Select]
(defun c:style_Update (/ st)

  (vl-load-com)

  (vlax-for st
               (vla-get-textstyles
                 (vla-get-activedocument (vlax-get-acad-object))
               )
    ;;  Old font file in CAPS
    (if (= (strcase(vla-get-fontfile st)) "SIMSUNB.TTF")
      (vl-catch-all-apply
      '(lambda ()
(progn
   (setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\Simplex_.ttf")))
   (vla-put-fontfile st fontfile)
   )
)
    )
  )
  )
  (princ)
)


I guess I am actually looking for a way to access the ttf's in simsun.ttc, but like I said, I really don't know very much.

Thank you all, again,
Dan

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: changing font of text style at startup
« Reply #16 on: November 06, 2017, 04:08:40 AM »
If you select the SimSun.ttc manually, what is then the fontfile property of the text tyle?

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #17 on: November 06, 2017, 09:40:29 AM »
If you select the SimSun.ttc manually, what is then the fontfile property of the text tyle?

If I manually change the font in the text style to SimSun and then run this
Code: [Select]
(vl-load-com)
(defun c:cf()
    ;; This example returns the current setting of
    ;; the FontFile property. It then changes the value, and
    ;; finally resets the value back to the original setting.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    (setq textStyle1 (vla-get-ActiveTextStyle doc))
   
    ;; Retrieve the current FontFile value
    (setq currFontFile (vla-get-FontFile textStyle1))
    (alert (strcat "The current value for FontFile is " currFontFile))
)
....I get the first screen capture, but then when i run this
Code: [Select]
;;  returns nil if not found, else font name if found
;;  TTF file names should have the extension already added
;;  "romant.ttf"
(defun find_font (fname / path font$)
  (setq path (getenv "windir"))
  (if (vl-position (substr path (strlen path)) '("/" "\\"))
    (setq path (strcat path "FONTS\\"))
    (setq path (strcat path "\\FONTS\\"))
  )
  (setq font$ (if (wcmatch fname "*\\*,*`.*")
                fname
                (strcat fname ".shx")
              )
  )

  (cond
    ((findfile font$) font$)
    ((and path (findfile (strcat path font$))) font$)
    (t nil)
  )
)
....I get the second capture.




roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: changing font of text style at startup
« Reply #18 on: November 06, 2017, 10:23:32 AM »
Try changing the FontFile property to "SimSun.ttf" programmatically. And if that works revise the 'findfile' portion of the code.

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #19 on: November 06, 2017, 10:37:33 AM »
Try changing the FontFile property to "SimSun.ttf" programmatically. And if that works revise the 'findfile' portion of the code.

It does not work. I think I am stuck hoping there is a VLISP process for unpacking a .ttc that I just can't find.

Thank you for the responses, Roy. I think I have a clearer target now.

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #20 on: November 21, 2017, 03:31:05 PM »
I did manage to break through on this....unfortunately, I was not very methodical, and I'm uncertain of exactly how I pulled it off, but I think that it could be worthwhile for someone down the road to know what I did to accomplish what I wanted, so here goes....

First, I tried to download a copy of the SimSun.ttf package w/out the *.ttc package.  Windows seemed to reject the installation of that file, because it knew it was already there.

Next, I searched for other programs that handle ttc's and found that the filetype uses an index for each of the ttf components of the ttc....so i started to mess w/ the code I was using to try to call the simsun.ttf. i.e.,
(setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\SimSun.ttf, 0")))
(setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\SimSun.ttf; 0")))
(setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\SimSun.ttf[0]")))

And then I threw a random Hail Mary:  (setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\SimSun.ttf")))...and the code worked.

I went back and checked the fonts, and I now had NSimSun.ttc that included a NSimSun.ttf and a SimSun.ttf and a SimSun_0.ttf.   I was unsure why the above code worked considering, but it did.

Now after 20 restarts or so, I have NSimSun.ttc and SimSun.ttc in my fonts, both contain the NSimSun.ttf and the SimSun.ttf with no independent SimSun_0.ttf to be found.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: changing font of text style at startup
« Reply #21 on: November 21, 2017, 03:45:34 PM »
Also check the registry to make sure the font is using the correct ttf file. Those numbered ttf files come from installing a font multiple times and if you install a wonky one, then you're hosed.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

If you're using Windows 10 and want to see the font files individually, you can paste this into Windows Explorer to do so:
\\%computername%\c$\Windows\Fonts
« Last Edit: November 21, 2017, 03:54:14 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #22 on: November 21, 2017, 04:13:34 PM »
Thank you for the heads up, Ron.....I do have the SimSun_0.ttf file in there.  I don't think I am in trouble, because I ran the code on a shared file that another user was able to open, use and plot w/out any trouble or font installations.  Is that a file I can simply delete for the future? 

I'm thinking that I was actually ready to roll when I tried to install the plain SimSun.ttf despite Windows' complaint, and my fancy index calls just kept me occupied for a few hours..... :idiot2: