TTF Text Font

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: TTF Text Font

Post by yorik »

Very nice macro, as usual Mario!

I would also like much to have the ShapeString ui to use the simple font chooser that other controls use in FreeCAD...

Unfortunately, that control returns only a name of a font: "Arial", "Times New Roman", etc... and Qt doesn't provide any way to retrieve the actual file of that font!! And given the different platforms (linux, mac, win) all manage that differently, and the fact that the file name can be different than the font name, and there can be different files for italic, bold,...) it becomes quickly a nightmare.

If you search for it on the net you'll find other coders pulling their hairs to find a solution to this, but I couldn't find any that would work for us, support all the platforms, etc
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: TTF Text Font

Post by mario52 »

hi
yorik wrote: Wed May 15, 2019 10:55 pm Unfortunately, that control returns only a name of a font: "Arial", "Times New Roman", etc... and Qt doesn't provide any way to retrieve the actual file of that font!!
this macro is different of the precedent macro (Window_fonts above)

this new macro (Macro_Fonts_Win10_PYMP) use the matplotlib tools for font : (extract of my macro)

Code: Select all

        ##https://matplotlib.org/_modules/matplotlib/font_manager.html
        if setSystemFonts == 0:
            files_All_Fonts = matplotlib.font_manager.findSystemFonts(pathSearch, "ttf")  # fait toutes les fontes ? ()
        else:
            files_All_Fonts = fontman.findSystemFonts(pathSearch)                         # fait toutes les fontes (et dans tous les sous dossiers)
and the return is : (see end line)

Code: Select all

#                    nameFamily    = matplotlib.font_manager.FontProperties(fname=fonte).get_family()            ##['sans-serif']
#                    nameStyle     = matplotlib.font_manager.FontProperties(fname=fonte).get_style()              #normal
#                    nameVariant   = matplotlib.font_manager.FontProperties(fname=fonte).get_variant()            #normal
#                    nameWeight    = matplotlib.font_manager.FontProperties(fname=fonte).get_weight()             #normal
#                    nameStretch   = matplotlib.font_manager.FontProperties(fname=fonte).get_stretch()            #normal
#                    nameFileComp  = matplotlib.font_manager.FontProperties(fname=fonte).get_file()              ##c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf
#                    nameSize      = matplotlib.font_manager.FontProperties(fname=fonte).get_size()               #10.0
                    nameName      = matplotlib.font_manager.FontProperties(fname=fonte).get_name()              ##Noto Naskh Arabic UI
#                    nameSizePoint = matplotlib.font_manager.FontProperties(fname=fonte).get_size_in_points()     #10.0
#                    nameSlant     = matplotlib.font_manager.FontProperties(fname=fonte).get_slant()              #normal
#                    namePattern   = matplotlib.font_manager.FontProperties(fname=fonte).get_fontconfig_pattern() #:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:file=c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf:size=10.0
the macro is dedicate for the Windows 10 (the window font is empty) users but is you testing it on Linux , Mac .... "merci"

PS: I discovered a bug ShapeString see here my precedent post would you please correct thanks (also with other font can work)

i search for the path with "éçèèà.." un casse tête
GlouGlou wrote: Tue May 14, 2019 5:42 pm Great!
rendu pas 100% pour toutes les fontes ! , merci

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: TTF Text Font

Post by yorik »

mario52 wrote: Thu May 16, 2019 9:42 am this new macro (Macro_Fonts_Win10_PYMP) use the matplotlib tools for font : (extract of my macro)
Aaah, interesting! I'll play a bit with that...
mario52 wrote: Thu May 16, 2019 9:42 am PS: I discovered a bug ShapeString see here my precedent post would you please correct thanks (also with other font can work)
Ok, fixing that now
pbisson
Posts: 10
Joined: Wed Oct 10, 2018 9:06 pm

Re: TTF Text Font

Post by pbisson »

I am using Windows 10 and FreeCAD 0.18. When I try to use the Draft|Shape from Text tool and I attempt to brows for a font file, no fonts are visible in the standard C:\windows\fonts folder. If I copy a font, say Arial.ttf, to my desktop folder, that font is visible when browsing for a font. I note that there are many fonts actually in the c:\windows\fonts folder, they just aren't visible to the font file browse dialog for some reason.

Perhaps this visibility problem is caused by the security system under Windows 10? I've tried running FreeCAD "as Administrator" with elevated security permissions, but that does not help. I've tried taking ownership of the fonts folder and it's contents, but that does not help either.

I could copy all the fonts I need into some new folder I myself create and sidestep, or work around, this problem. But this does not seem to be a very good solution, IMHO. I think it would be better for FreeCAD to find and use the designated font "database" in the standard C:\windows\fonts folder. That seems to be the expected behavior, is it not?

I notice other people in this thread have similar problems in this area. Is this recognized as a bug? Is it even recognized as a problem? Does someone else have a better work-around (other than copying fonts) for this problem?
pbisson,
casual FreeCAD user and fan
UR_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: TTF Text Font

Post by UR_ »

I'm using win 10 version 1903 too.

And this is file open dialog from DraftWB->Shapestring->Font file button:

Annotation 2019-06-16 203025.png
Annotation 2019-06-16 203025.png (53.24 KiB) Viewed 2355 times

Done with this workflow:
- open command prompt as administrator
- execute attrib -r - s c:\windows\fonts
- execute takeown /a /f c:\windows\fonts

that's all.

But caution, furthermore administator has ownership and not TrustedInstaller. :roll:
pbisson
Posts: 10
Joined: Wed Oct 10, 2018 9:06 pm

Re: TTF Text Font

Post by pbisson »

Thanks UR_. I was doing basically the same thing, but on the contents of the \fonts folder, not the folder itself.

After I changed the attributes and set ownership to the adminstrators group on the folder itself, the font dialog worked properly.

Much appreciated.
pbisson,
casual FreeCAD user and fan
User avatar
papyblaise
Veteran
Posts: 8015
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: TTF Text Font

Post by papyblaise »

In front with this same problem whith Windows's fonts "vous n'étes pas autotriser..." , I decided to create a new folder in Freecad "Lib/Font and carbon copy the Windows 's font on this , and from this date finish problems :!:
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: TTF Text Font

Post by mario52 »

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
LazarusLeo
Posts: 1
Joined: Mon Oct 28, 2019 5:08 pm

Re: TTF Text Font

Post by LazarusLeo »

Sans serif fonts are popular font styles used everywhere for their clean, modern appearance. They are different from so-called "wheelbase" fonts because they do not have these small lines protruding from the ends and bases of the letter (that is to say, serifs). Therefore, we include the French word sans (which means "without").
User avatar
wandererfan
Veteran
Posts: 6324
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: TTF Text Font

Post by wandererfan »

UR_ wrote: Sun Jun 16, 2019 6:42 pm Done with this workflow:
- open command prompt as administrator
- execute attrib -r - s c:\windows\fonts
- execute takeown /a /f c:\windows\fonts

that's all.

But caution, furthermore administator has ownership and not TrustedInstaller. :roll:
See this: https://www.forum.freecadweb.org/viewto ... 10#p339884 to solve without changing ownership.
Post Reply