Author Topic: Changing Fonts  (Read 1596 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1361
Changing Fonts
« on: November 23, 2021, 08:02:44 PM »
The attached routine (FontSub and FontRemap commands are the issues) are supposed to remap all fonts and styles that use RomanS or RomanS_New to arial.ttf, but sometimes it remaps to  seemingly random fonts, anyone have any ideas why?
« Last Edit: November 23, 2021, 08:06:48 PM by cmwade77 »

mhupp

  • Newt
  • Posts: 172
Re: Changing Fonts
« Reply #1 on: November 24, 2021, 07:29:08 AM »
Just a guess here quickly looking over the code. (stripmtext SS "F") seems to be stripping the font of mtext and changing it to whatever the current text style font is.
If you run that command and select some mtext you can just uncheck font. make sure you have remember checked and should fix the problem.

Maybe the F means font? idk maybe remove that line if its still a problem.

-edit-

yep "F" = Font
« Last Edit: November 24, 2021, 07:41:08 AM by mhupp »

tombu

  • Bull Frog
  • Posts: 270
  • ByLayer=>Not0
Re: Changing Fonts
« Reply #2 on: November 24, 2021, 07:43:05 AM »
Curious why you added these functions at the end of the StripMtext code.

FontSub, CivilSub and FontRemap are supposed to remap a lot more fonts and styles than just RomanS or RomanS_New. Are you sure those are random? Can you list any that were modified that shouldn't have been?
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #3 on: November 24, 2021, 11:22:54 AM »
Curious why you added these functions at the end of the StripMtext code.

FontSub, CivilSub and FontRemap are supposed to remap a lot more fonts and styles than just RomanS or RomanS_New. Are you sure those are random? Can you list any that were modified that shouldn't have been?
Those are also changed, it is just the RomanS and RomanS_New that don't always get changed correctly for some reason. Basically, we are in the process of a CAD Standards changeover to change to TTF due to new DSA requirements that anywhere we reference a sheet, there must be a link and some other plan checkers that now require all text be machine readable, so easiest to do a blanket change.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #4 on: November 24, 2021, 11:24:13 AM »
Just a guess here quickly looking over the code. (stripmtext SS "F") seems to be stripping the font of mtext and changing it to whatever the current text style font is.
If you run that command and select some mtext you can just uncheck font. make sure you have remember checked and should fix the problem.

Maybe the F means font? idk maybe remove that line if its still a problem.

-edit-

yep "F" = Font
But I wouldn't think it should be changing the text style definition itself, just removing font overrides from the mtext, which is what I want it to do.

And yes, I am sure it is random, as it sometimes changes to some Aribac font or something like that, which makes no sense.
« Last Edit: November 24, 2021, 11:27:37 AM by cmwade77 »

danAllen

  • Newt
  • Posts: 46
Re: Changing Fonts
« Reply #5 on: November 24, 2021, 12:10:21 PM »
Can you share how the mtext is remapped to random fonts? Is that in the edit box that you're seeing that?
When I have mtext formatting problems, I edit the text with notepad/textpad by changing the MTEXTED variable temporarily so I can see all the raw codes. (I have a special edit routine that does this automatically.)

Also curious how you are managing to add links to sheet references. I'd like to do that but I don't know an easy efficient way to do so.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #6 on: November 24, 2021, 12:23:33 PM »
The mtext isn't the issue, it is the style definition.

After running the command, I type style and check the text style, it will have different fonts assigned randomly to the style.

danAllen

  • Newt
  • Posts: 46
Re: Changing Fonts
« Reply #7 on: November 24, 2021, 01:33:21 PM »
got it, was confused by stripmtext lisp beginning your file

On Bricscad v15, this worked for me:
Code: [Select]
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "Calibri") (4 . ""))

: (subfont "calibri.ttf" "arial.ttf")

Changing: calibri.ttf to:  arial.ttf
: STYLE
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "C:\\WINDOWS\\fonts\\arial.ttf") (4 . ""))

Though I don't like that the font path is hard-coded into the style. I assume that will cause conflicts when the drawing is opened with different OS configuration.

If you have an example drawing with the fonts you want to check, post and I can test.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #8 on: November 24, 2021, 01:35:51 PM »
got it, was confused by stripmtext lisp beginning your file

On Bricscad v15, this worked for me:
Code: [Select]
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "Calibri") (4 . ""))

: (subfont "calibri.ttf" "arial.ttf")

Changing: calibri.ttf to:  arial.ttf
: STYLE
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "C:\\WINDOWS\\fonts\\arial.ttf") (4 . ""))

Though I don't like that the font path is hard-coded into the style. I assume that will cause conflicts when the drawing is opened with different OS configuration.

If you have an example drawing with the fonts you want to check, post and I can test.
Unfortunately, the one that I am having issues with I can't legally share, let me see if I can find another file that is doing this.

danAllen

  • Newt
  • Posts: 46
Re: Changing Fonts
« Reply #9 on: November 24, 2021, 01:46:22 PM »
Just erase everything but don't purge the text styles? Also OK to PM me.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #10 on: November 24, 2021, 03:08:58 PM »
Just erase everything but don't purge the text styles? Also OK to PM me.
I sent you a PM.

danAllen

  • Newt
  • Posts: 46
Re: Changing Fonts
« Reply #11 on: November 24, 2021, 03:53:45 PM »
I had to edit the lisp to point to where the fonts could be found on my system, some were at "C:\\Users\\Dan\\AppData\\Local\\Microsoft\\Windows\\Fonts\\"
Also windows renamed my font to have a hyphen, while your lisp did not: "Helvetica-Bold.ttf"

After that, using c:fontsub -  it seemed to work, attached are screen shots of the styles before and after. c:fontremap worked also, only changed one other style so I didn't save an image.

sorry - no ideas. I would work through the code of a trouble font substitution and see what happens to look for the bug.

also, had to use DWG TrueView to convert down to v2013 so I could open. No idea if that changed anything.

tombu

  • Bull Frog
  • Posts: 270
  • ByLayer=>Not0
Re: Changing Fonts
« Reply #12 on: November 27, 2021, 11:33:02 AM »
I've always used T.Willey's Merge text styles (or change text styles) for the Text Styles then used StripMtext code as needed on Mtext.
http://www.theswamp.org/index.php?topic=17659.0;all
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #13 on: November 29, 2021, 01:42:56 PM »
If I list the font with LISP, it is claiming to use the correct font, but the style dialog box does not show the font being used. Here is a video:
https://www.awesomescreenshot.com/video/6210540?key=9b078b584c20187b0603a4fb050f9d0f

Here is updated code:
Code: [Select]
(vl-load-com)
(defun C:FontSub ( / doc)
  ;Format for List: <Font to Remap To> <All Fonts to remap>
  (subfont
    (list       
      (list "arial.ttf" "romans.shx" "romand.shx" "simplex.shx" "osafrac.shx" "txt.shx" "RomanS_New.ttf")
      ;(list "Helvetica Bold.ttf" "helvbld.shx" "hlvm1d.shx" "helvm2.shx" "x-hlvm1d.shx")
    )
  )
)



(defun SubFont (FontList / doc Ct FontChangeList FontToChange FontToChangeBase DestinationFontName AllStyles DestinationFontBase CurrentStyleFile CurrentStyleBase CurrentStyleName tStyle)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (foreach FontChangeList FontList
    (setq Ct 1
          DestinationFontName (nth 0 FontChangeList)
    ) 
    (if (not (setq DestinationFontPath (findfile (strcat (getenv "WINDIR") "\\fonts\\" DestinationFontName))))
      (setq DestinationFontPath (findfile DestinationFontPath))
    )
    (if DestinationFontPath
      (progn
        (setq DestinationFontBase (vl-filename-base DestinationFontPath))
        (while (< Ct (length FontChangeList))
          (setq FontToChange (strcase (nth Ct FontChangeList))
                FontToChangeBase (strcase (vl-filename-base FontToChange))
                Ct (+ Ct 1)
                AllStyles (vla-get-textstyles doc)
          )
          (vlax-for tStyle AllStyles
            (setq CurrentStyleName (vla-get-name tStyle)
                  CurrentStyleFile (vla-get-fontfile tStyle)
                  CurrentStyleBase (vl-filename-base CurrentStyleFile)
            )
            (if (and (or (= (strcase CurrentStyleFile) FontToChange) (= (strcase CurrentStyleBase) FontToChangeBase)) (not (wcmatch CurrentStyleName "*|*")))
              (progn
                (vla-put-fontfile tStyle DestinationFontPath)
                (princ "\nChanged ") (princ CurrentStyleName) (princ " to ")(princ (vla-get-fontfile tStyle))(princ " as defined ")(princ DestinationFontBase)(princ "\n")
              )
            )
          )
        );end while
      );end Progn
    );end if
  );end foreach
  (c:ListFonts)
  (vla-endundomark doc)
  (princ)
);end defun

(defun c:ListFonts (/ AllStyles doc tStyles)
  (setq doc (vla-get-activedocument (vlax-get-acad-object))
        AllStyles (vla-get-textstyles doc)
  )
  (vlax-for tStyle AllStyles
    (if (not (wcmatch (vla-get-name tstyle) "*|*"))
      (progn
        (princ "\nStyle: ")(princ (vla-get-name tstyle)) (princ " -> Font: ")(princ (vla-get-fontfile tStyle))
      )
    )
  )
)

EDIT: It appears the correct font is getting used, it just displays wrong in the User Interface elements, such as the Style dialog and the ribbon when editing text.
« Last Edit: November 29, 2021, 02:58:22 PM by cmwade77 »

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Changing Fonts
« Reply #14 on: November 29, 2021, 01:44:07 PM »
I've always used T.Willey's Merge text styles (or change text styles) for the Text Styles then used StripMtext code as needed on Mtext.
http://www.theswamp.org/index.php?topic=17659.0;all
His is a lot more complex than what I want, I simply want to change the fonts being used, for a variety of reasons I can't merge styles, as the style names have to remain for other LISP Compatibility.