WIP: Outline font support
This WIP is intended for KiCAD 7, should it be deemed worthy.
I'm leaving all the text about Hershey fonts here for posterity. However, this MR has evolved into something other than that, namely "outline font support". See below for discussion.
KiCAD 5 (and 6) uses a font called "Newstroke" for all schematic and board text items. This font is derived from one of the Hershey fonts (which see: https://en.wikipedia.org/wiki/Hershey_fonts ). However, it would be nice to use other fonts for silkscreen items. The easiest to implement are the other Hershey fonts, since the reader for Newstroke basically reads the Hershey format. The Newstroke reader code was used to implement a reader for the original Hershey format as found at eg. https://emergent.unpythonic.net/software/hershey
The Hershey fonts are rather anachronistic, and there are not that many of them; I am submitting this in the hope that this work paves the way so that one day other font formats (such as OpenType) may be used for silkscreen text.
As things stand now, the new code works with pcbnew and 3d-viewer, as well as plot/export to PDF/Postscript/Gerber/SVG.
There are a number of issues to be resolved before this is production ready, such as:
- where to put the fonts?
- Currently, I'm assuming the fonts are magically installed in a subdirectory called "fonts" in the user config directory. The Hershey fonts have a very liberal licence, so they can be distributed with KiCAD, and only take up about 280kB.
- how to use different fonts?
- If a PCB text item starts with "${FONT:timesi}" (where "timesi" is the name of the desired Hershey font), that font is used for the text item in question. Multiple fonts per text item are not implemented. If the FONT "variable" appears anywhere else except at the beginning, it won't be used. I implemented this hack because it meant I did not need to worry about GUI implications, or changing the save file format. However, it is rather hacky. And by the way, schematic text items are not supported (for now).
- should other items be eligible for font change?
- I have only implemented the $FONT hack for PCB text items, because I wanted to limit the repercussions of this change, and also because I think that is the most likely use case.
- should multiple fonts per text item be supported?
- Probably not. The approach I took would require a lot of rethinking.
- what to do about missing glyphs?
- The original Hershey fonts support ASCII only. There are fonts called cyrillic, greek, japanese etc. but these work with the ASCII encoding, so good luck trying to figure out how to write Greek or Russian with them. Umlauts etc. are of course not present at all, or if there are independent diacriticals (I think there are some), characters with diacriticals do not exist.
- and probably a lot of things I haven't even thought of
Merge request reports
Activity
The reason we don't do this is because we are a multi-lingual system, so implementing ASCII-only fonts is a non-starter.
Also, the current system of embedding fonts is at its limit. This currently takes much longer to initialize than we would like. External fonts using established type libraries instead of our own implementation will resolve this. Adding more built-in fonts will be problematic from a loading perspective.
In fact there are 2 use cases:
- Fonts for schematic: this is the most easy (famous words) case to solve: text sizes are not so critical, and to be able to use a given font is a very good enhancement.
- Fonts for Boards: this is the hard case to solve: text sizes are critical, and texts must be compatible with Gerber constraints: clearance, min thickness ... OTOH, asthetic criterias are not a major constraint. And waht happens if a font is not availlable on a computer.
My opinion is first use TTF, OTF or any other type in Eeschema and solve all issues, and after all issues are solved (displaying and printing texts, missing fonts), try to solve specific issues in Pcbnew. The first points is already a very hard work.
My opinion is first use TTF, OTF or any other type in Eeschema and solve all issues, and after all issues are solved (displaying and printing texts, missing fonts), try to solve specific issues in Pcbnew.
After working with this quite a bit I have come to the conclusion that Eeschema outline font support is not possible without a major redesign of text item handling. Pcbnew on the other hand is doable with much less effort. A lot of the work done on pcbnew can of course be used in eeschema as well, but there are many issues that are specific to eeschema.
added 21 commits
-
8093ca32...cf2dd0bd - 18 commits from branch
kicad/code:master
- bb47b833 - Merge remote-tracking branch 'upstream/master'
- 0d29f876 - Merge branch 'master' into strokefont
- 7b0738cb - Merge remote-tracking branch 'upstream/master' into strokefont
Toggle commit list-
8093ca32...cf2dd0bd - 18 commits from branch
And waht happens if a font is not availlable on a computer.
Presumably exactly the same thing as when a MS Word file is passed around.
Font embedding is a higher-level issue than vector font support; I'll leave that one for others to ponder.
The reason we don't do this is because we are a multi-lingual system, so implementing ASCII-only fonts is a non-starter.
There are many (especially non-Latin, eg. Arabic) scripts that KiCAD does not support.
Looks like it will not be insurmountably difficult to add support for TrueType etc. - including the aforementioned Arabic script. More work remains to be done, as you can see from the attached picture.
Edited by Ola Rinta-KoskiPresumably exactly the same thing as when a MS Word file is passed around.
No. The fonts that are included with MS Word have specific license exemptions that allow them to be included in the file, as certain conditions are met. (https://docs.microsoft.com/en-us/typography/fonts/font-faq) These conditions cannot be met by KiCad and so we cannot support font embedding unless we can restrict the fonts to those with an open license.
This becomes a can of worms that may not be worth opening. We can distribute a set of open fonts with the appropriate licenses and we can discuss whether we would want to allow linking to system fonts.
No. The fonts that are included with MS Word have specific license exemptions
I wasn't talking about included fonts, in fact I was talking specifically about fonts not distributed with Word, and then not choosing for one reason or another (like simply not knowing one can do such a thing) to embed them in the Word document (which in my experience is often the case). Sorry for not making that clear.
I could image us keeping the font text as a set of filled polygons that would allow the board to be opened on any computer. But if you edit the text, it would need to take a font from your machine.
PDF font subsetting works more or less like that, without the editing bit.
Edited by Ola Rinta-Koski
I suggest that fonts such as
TTF/OTF
can be set to a global font or a local font path.Global font file: select the font file in the
system
.Partial font file: add a
fonts
folder in the KiCad project to store users' own font files.Do you think this is okay?
Edited by taotierenmentioned in issue #2441 (closed)
added 330 commits
-
7b0738cb...07d4a280 - 258 commits from branch
kicad/code:master
- d54b4e9d - start of Truetype support
- 00c52bec - further work on ttf support; added Freetype/HarfBuzz libs
- 7b69e6cc - add OpenType (otf), more HarfBuzz code
- 37a6296a - Merge remote-tracking branch 'upstream/master' into strokettf
- f3f4e7ec - piecewise linear approximation for Bezier curves; renamed...
- 61100690 - piecewise linear approximation for Bezier curves; renamed...
- f3ff2e6f - renamed class TRUETYPE_FONT -> OUTLINE_FONT
- d633c1f7 - renamed truetype->outline
- ab21d514 - contour approximation a bit more accurate, seems to give poor results on eg. Comic Sans
- 730e73ac - all outline code moved to outline_font.cpp
- bbf06218 - some typedefs to make life a bit easier/saner
- 67fb64e5 - fixes to private fn signatures
- ece51871 - typedefs moved to superclass
- 3cc0a8ad - convenience function; avoids code duplication in addShapeWithClearance() for PCB_TEXT
- d7482d8f - started work on outline text rendering, added new callback for complete...
- c6ac9132 - added FillPolyline() and outline callback (see create_3dgraphic_brd_items.cpp)...
- f6845bb4 - dummy GAL is now a subclass of GAL (which now has a pure virtual fn)
- 22e735c9 - fn renamed in BASIC_GAL
- 65ab06ee - font caching moved here; fn to query font stroke/outline type
- 677cad5b - font caching moved to FONT
- f894d32f - dummy implementation of FillPolyline (pure virtual in GAL) which just calls...
- 82cf6ea9 - quadratic Beziers converted to cubic and further to straight segments with...
- 3d8162bd - Draw() is now not a constant function (here would be OK but outline fonts get cached)
- 415b60e3 - outline callbacks set up here
- edb153aa - support for outline fonts; text only drawn if not empty
- 0d1edc5f - FillPolyline implementation
- 305364c6 - FillPolyline implementation (just calls drawPolyline)
- 7a7802e0 - Draw() no longer const because of caching
- b168bfad - Draw() no longer const because of caching
- 121a9ca5 - outline callback
- 94ff335d - outline font support
- 8fe64fea - fixes for merge conflict
- 4d60d226 - Merge remote-tracking branch 'upstream/master' into strokettf
- 8c0504bf - git fix-format
- 6e0c4bb3 - Merge remote-tracking branch 'upstream/master' into strokettf
- 6ed46f97 - still merging
- 2800102e - still merging
- 453639c2 - typedef'd outline callback for readability
- 2fdb323f - typedef'd outline callback for readability
- 77970420 - PCB text items in outline fonts now converted to 2d triangles for 3d viewer in outline callback
- 6e8f3de6 - fix for mirrored pcb text
- b33c7213 - drawPolyline methods rearranged
- ed4a8a9f - drawPolyline for std::vector<VECTOR2D>
- 6efdc75d - removed debug printouts
- 5ae91a3e - removed debug printouts
- f7dee400 - FillPolyline not actually needed but DrawPolyline for std::vector<VECTOR2D> is
- f053216d - FillPolyline not actually needed but DrawPolyline for std::vector<VECTOR2D> is
- 9efeb00a - FillPolyline not actually needed but DrawPolyline for std::vector<VECTOR2D> is
- b1873c4d - FillPolyline not actually needed but DrawPolyline for std::vector<VECTOR2D> is
- 5a14d220 - FillPolyline not actually needed but DrawPolyline for std::vector<VECTOR2D> is
- 7f5f2b25 - Merge remote-tracking branch 'upstream/master' into strokettf
- b98a4955 - format changes caused by merge
- 86640347 - no longer need to explicitly turn fill on as this has to be handled at caller anyway
- 8186245c - for each contour of a glyph, figure out whether it is part of the glyph outline, or a hole
- e634185d - for each contour of a glyph, figure out whether it is part of the glyph outline, or a hole
- 4a4ff085 - Merge remote-tracking branch 'upstream/master' into strokettf
- 2bed2c83 - merge from upstream/master finalized
- cb59fac7 - pcbnew main display and gerber output work with freetype, 3d viewer does not;...
- d71f26df - fixed typo in global fn name
- fa4f60c0 - winding now correct for all contours
- 67e45f39 - checkpoint: pcbnew & Gerber output more or less working, 3d viewer does not...
- 25bced1d - multi-outline (eg. aumlaut) glyphs displayed but still without holes
- 5cf11201 - 3d viewer shows outline fonts correctly - does not show Newstroke at the...
- 53001eb9 - untouched copy from https://github.com/mapbox/earcut.hpp
- 08b7610e - outstanding issues with outline font processing; Gerber output seems to have problems
- a5e91bff - Merge remote-tracking branch 'upstream/master' into strokettf-merge
- 51cb3800 - finalized merge
- cc53ac90 - moved to font/ subdir
- 4cd680b6 - font stuff moved to font/ subdir
- 790a21c5 - removed unused code, added back stroke font PCB text items
- 95f8fb81 - font stuff moved to font/ subdir
- 3d0f810d - updated to current + merged branch outlinefont
Toggle commit list-
7b0738cb...07d4a280 - 258 commits from branch
Some of the many outstanding issues:
- fonts with glyphs that are self-intersecting are not handled properly
- no work has been done on eeschema
- font sizing needs more attention (but different fonts will always appear to be of different sizes even if the glyphs are the same size in mm)
- bold/italic/etc. does not work for outline fonts
- Resolved by Thomas Pointhuber
Can
Hershey_fonts
display Chinese completely? What's the effect of the display?
added 5 commits
-
3d0f810d...82ecb0f7 - 2 commits from branch
kicad/code:master
- 7b4ff3c8 - fonts with cubic splines now supported; moved outline decomposition to class...
- 319f7847 - deleted unused code
- ee805e9d - Merge remote-tracking branch 'upstream/master' into strokefont
Toggle commit list-
3d0f810d...82ecb0f7 - 2 commits from branch
- Resolved by Ola Rinta-Koski
Hello. I compiled the AUR package using the PR you submitted.
There is no TTF/OTF font option after installation.
Error message
ASSERT INFO: ./src/common/wincmn.cpp(3270): assert "!wxMouseCapture::IsInCaptureStack(this)" failed in CaptureMouse(): Recapturing the mouse in the same window? BACKTRACE: [1] wxWindowBase::CaptureMouse() [2] make_fcontext
Version information:
Application: Pcbnew Version: (5.99.0-8620-g3d0f810d3b), debug build Libraries: wxWidgets 3.0.5 libcurl/7.74.0 OpenSSL/1.1.1i zlib/1.2.11 zstd/1.4.8 libidn2/2.3.0 libpsl/0.21.1 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.41.0 Platform: Linux 5.4.91-1-lts x86_64, 64 bit, Little endian, wxGTK, KDE, x11 Build Info: Date: Jan 23 2021 06:17:28 wxWidgets: 3.0.5 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24 Boost: 1.75.0 OCC: 7.5.0 Curl: 7.74.0 ngspice: 33 Compiler: GCC 10.2.0 with C++ ABI 1014 Build settings: KICAD_SCRIPTING=ON KICAD_SCRIPTING_MODULES=ON KICAD_SCRIPTING_PYTHON3=ON KICAD_SCRIPTING_WXPYTHON=ON KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON KICAD_SCRIPTING_ACTION_MENU=ON KICAD_USE_OCC=ON KICAD_SPICE=ON KICAD_STDLIB_DEBUG=OFF KICAD_STDLIB_LIGHT_DEBUG=ON KICAD_SANITIZE=OFF
Compiled AUR package:
https://github.com/taotieren/kicad_arch/actions/runs/505239223
PKGBUILD info:
# https://github.com/taotieren/kicad_arch/blob/main/PKGBUILD # Maintainer: Edward Pacman <edward at edward-p dot xyz> # Contributer: Nick Østergaard <oe.nick at gmail dot com> pkgname=kicad-test _langpack=kicad-i18n-test replaces=(${_langpack}) pkgver=r20075.2d1d16d7a2 pkgrel=1 pkgdesc="Electronic schematic and printed circuit board (PCB) design tools" arch=('i686' 'x86_64') url="http://kicad-pcb.org/" license=('GPL') depends=('wxgtk3' 'python' 'boost-libs' 'glew' 'curl' 'ngspice' 'opencascade' 'python-wxpython') makedepends=('git' 'cmake' 'glm' 'zlib' 'mesa' 'boost' 'swig') optdepends=('kicad-library: for footprints and symbols' 'kicad-library-3d: for 3d models of components') conflicts=('kicad' 'kicad-bzr') provides=('kicad') source=("${pkgname}"'::git+https://gitlab.com/rockola/kicad.git') md5sums=('SKIP') pkgver() { cd "${srcdir}/${pkgname}" printf "r%s.%s" "$(git rev-list HEAD --count --first-parent)" "$(git rev-parse --short HEAD)" } build() { cd "${srcdir}/${pkgname}" git switch -c test ee805e9d mkdir -p build cd build # -DCMAKE_BUILD_TYPE=Release cmake .. -DCMAKE_BUILD_TYPE=Debug \ -DKICAD_STDLIB_LIGHT_DEBUG=ON \ -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_INSTALL_LIBDIR=lib \ -DKICAD_USE_OCE=OFF \ -DKICAD_USE_OCC=ON \ -DKICAD_BUILD_I18N=ON \ -DBUILD_GITHUB_PLUGIN=ON \ -DKICAD_SCRIPTING=ON \ -DKICAD_SCRIPTING_MODULES=ON \ -DKICAD_SCRIPTING_ACTION_MENU=ON \ -DKICAD_SCRIPTING_PYTHON3=ON \ -DKICAD_SCRIPTING_WXPYTHON=ON \ -DwxWidgets_CONFIG_EXECUTABLE=/usr/bin/wx-config-gtk3 \ -DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON make # cd "${srcdir}/${pkgname}/translation" # mkdir -p build # cd build # cmake .. -DCMAKE_INSTALL_PREFIX=/usr # make } package() { cd "${srcdir}/${pkgname}" cd build make DESTDIR="${pkgdir}" install }
mentioned in merge request !645 (closed)
added 67 commits
-
ee805e9d...9f18fee1 - 58 commits from branch
kicad/code:master
- 7def4661 - Merge remote-tracking branch 'upstream/master' into strokefont
- 5b16119d - earcut.hpp moved (included not only from 3dviewer); added triangulate.h which...
- c2658707 - moved
- 6b892373 - font interface changed; instead of font name being passed around, EDA_TEXT...
- 266813b6 - Merge remote-tracking branch 'upstream/master' into strokefont
- 3b96625b - upstream/master merge finalized
- 49eb23bf - outline fonts work in eeschema (for some definition of 'work'); PDF plot from...
- 68312fb6 - Merge remote-tracking branch 'upstream/master' into strokefont
- 61ecfb1d - upstream/master merge finalized
Toggle commit list-
ee805e9d...9f18fee1 - 58 commits from branch
Schematic Chinese display exception:
PDF Chinese display exception:
PCB Chinese display is normal:
Gerber Chinese display is normal:
Application: Eeschema Version: (5.99.0-8664-g49eb23bffd), debug build Libraries: wxWidgets 3.0.5 libcurl/7.74.0 OpenSSL/1.1.1i zlib/1.2.11 zstd/1.4.8 libidn2/2.3.0 libpsl/0.21.1 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.41.0 Platform: Linux 5.4.91-1-lts x86_64, 64 bit, Little endian, wxGTK, KDE, x11 Build Info: Date: Jan 25 2021 13:05:17 wxWidgets: 3.0.5 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24 Boost: 1.75.0 OCC: 7.5.0 Curl: 7.74.0 ngspice: 33 Compiler: GCC 10.2.0 with C++ ABI 1014 Build settings: KICAD_SCRIPTING=ON KICAD_SCRIPTING_MODULES=ON KICAD_SCRIPTING_PYTHON3=ON KICAD_SCRIPTING_WXPYTHON=ON KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON KICAD_SCRIPTING_ACTION_MENU=ON KICAD_USE_OCC=ON KICAD_SPICE=ON KICAD_STDLIB_DEBUG=OFF KICAD_STDLIB_LIGHT_DEBUG=ON KICAD_SANITIZE=OFF
@taotieren can you paste the Chinese string you used here (or somewhere else I can access it if it can't be pasted here) so I can use it for testing?
OK, I'm using actions to compile it, and it will be tested after compiling. thanks.
2021年2月9日 00:48,Ola Rinta-Koski gitlab@mg.gitlab.com写道:
-
An exception is displayed when the text is placed for the first time in the schematic (the same as the schematic exception above).
-
Click the placed text content / adjust the height of the text again, and the Chinese content will display normally.
PDF Chinese display exception:
Application: Eeschema Version: (5.99.0-8692-g61ecfb1d94), debug build Libraries: wxWidgets 3.0.5 libcurl/7.74.0 OpenSSL/1.1.1i zlib/1.2.11 zstd/1.4.8 libidn2/2.3.0 libpsl/0.21.1 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.41.0 Platform: Linux 5.4.91-1-lts x86_64, 64 bit, Little endian, wxGTK, KDE, x11 Build Info: Date: Jan 25 2021 13:12:31 wxWidgets: 3.0.5 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24 Boost: 1.75.0 OCC: 7.5.0 Curl: 7.74.0 ngspice: 33 Compiler: GCC 10.2.0 with C++ ABI 1014 Build settings: KICAD_SCRIPTING=ON KICAD_SCRIPTING_MODULES=ON KICAD_SCRIPTING_PYTHON3=ON KICAD_SCRIPTING_WXPYTHON=ON KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON KICAD_SCRIPTING_ACTION_MENU=ON KICAD_USE_OCC=ON KICAD_SPICE=ON KICAD_STDLIB_DEBUG=OFF KICAD_STDLIB_LIGHT_DEBUG=ON KICAD_SANITIZE=OFF
-
@taotieren eeschema is nowhere near usable yet, I have only started looking into it. If you wish to give the current version a go, you should limit any testing to pcbnew and its outputs.
Multi-line and justification currently doesn't work. I wonder if it would require some extra work to support.
Edited by RigoLigoRLC