pcb

FreeType2 fonts

Bug #699460 reported by Ineiev
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
pcb
New
Wishlist
Unassigned

Bug Description

General features

First patches introduce multiple fonts per board; every text
has a pointer to it's font; the font for a new is selected
in the text input window; I also added a field for
the font scale there.

Then different text layouts are introduced.
Texts may be vertical or horizontal; the layout also may be
`reverse': for horizontal layouts this means right-to-left;
for vertical --- donwside-up.
(http://ineiev.users.sourceforge.net/pcb/graph/layout.png)
(the figure shows an optimistic case for a horizontal font turned
vertically: in general, the letters are not adjusted horizontally).

A new font type added, based on FreeType2 library. TTF and Type1
fonts seem to work, PCF don't (most probably, I load them
incorrectly).

Kerning should work for horizontal layouts
(http://ineiev.users.sourceforge.net/pcb/graph/kerning.png)

FreeType does not support kerning for vertical layouts,
and actually I have no idea if the implementation may be used
for such scripts.

  Glyphs rendering

At first I rendered them with `vertical' lines, like this:
(http://ineiev.users.sourceforge.net/pcb/graph/fill.png)

This was the most simple way, though small characters become
unreadable too soon.

Then I learnt FreeType glyphs had outline structures and
drawed them with lines:
(http://ineiev.users.sourceforge.net/pcb/graph/outline.png)

The next way was to join outlines with fills:
(http://ineiev.users.sourceforge.net/pcb/graph/full.png)

The `vertical' lines don't fill the outlines very good, some
small spaces remain; probably, something should be adjusted.

At last, I tried to do it with polygons:
(http://ineiev.users.sourceforge.net/pcb/graph/poly.png)

I don't do it clearly, because some contours need to be
added, other subtracted, and it is not evident to me how
to do it in real time.

Besides that, I think lines look more realistic, because
the polygons are not restricted with design rules;
the lines are.

  Cyrillic texts

The latest example demostrated a Cyrillic font; the implementation
matches this script quite well; some fonts lacked `ж' glyph;
no other inconveniences.

  More examples

  Polytonic Greek

(http://ineiev.users.sourceforge.net/pcb/graph/grdjvu.png)
There may be some problems: first, the implementation does not
support combining characters, so there may be difficulties
when entering accented letters; I entered them
via Gnome character map application.

Also, once I could not pull `μ' glyph from a font,
though it was present; probably something wrong
with that font mapping.

  Devanagari

(http://ineiev.users.sourceforge.net/pcb/graph/devanagari.png)
The consonants are not joined into ligatures (this was expected);
however, it puts viramam where it makes sence; it even adds
vowels (much better than I expected).
`i short' is put in a wrong place: I actually wrote
an incorrect sequence to force it hang where it should,
e.g. "-ko(i)va-" instead of "-kovi-".

  Afro-Asiatic scripts

(http://ineiev.users.sourceforge.net/pcb/graph/ar.png)
I really can't tell how usable it is for tfel-ot-thgir scripts;
I reproduced a word, I don't know how correctly.
I checked "reverse" checkbox in the text input window and
dragged the letters from Gnome character map.
Some letters take several places in the map; my font accepted
one of them and rejected the rest.

  Some notes on usage

To load a font, use LoadFreetype action,
like this: LoadFreetype(some_font.pfb); it will be added to
the font list of the current board. Every font in the list
has use counter, it will be embedded when saving the board
if some texts use it.

Different rendering options (outlines, fill, polygons)
are switched with defines in src/ft2font.c

  Final remarks

Once I thought whether it would be better to use pango instead
of freetype; it would solve problems with combining character,
but it has the next disadvantages:
first, it is a stronger dependence;
second, it renders to bitmaps only, whereas having
vectored outlines is important when the characters grow small.

These patches can hardly be used in practice,
because they change PCB file format, so mainstream PCB won't
read the files, saved by the patched program.

Tags: sf-patches
Revision history for this message
Ineiev (ineiev) wrote :
Revision history for this message
Ineiev (ineiev) wrote :
Revision history for this message
Ineiev (ineiev) wrote :

Next version of the patchset: fixed some bugs, added some
usability handles, a particular version of FreeType2
is incorporated to produce repeatable renderings.

NB I cut off extern/freetype-2.3.9.tar from
0006-implement-FreeType2-fonts-FILE-FORMAT-CHANGED.patch;
that file made the patch too long to post on SF Tracker;
it is just unbzip22ed FreeType release archive

patch;
that file made the patch too long to post on SF Tracker;
it is just unbzip22ed FreeType release archive

Updated notes on usage follow.

The patchset abstracts font structures; enables multiple fonts
in single board; introduces new font types, FreeType2 and QCAD

It tries to save files compatibly with unpatched versions of PCB
when no new features are used, but in other cases the mainstream PCB
can't read these files.

New actions are introduced:

ListFonts():
  all loaded fonts are enumerated in PCB Log

ReportFont(font_index)
  font properies are reported

FontProperies(font_index)
  changable font properties are assigned in a window;
  the properties set includes at least user-defined font label

ShowFont(font_index,rows_number,cols_number,first_glyph_index,
  row_separation,col_separation,scale)
  generates a board where the font glyphs are shown in a table;
  the glyphs are referenced with escaped sequences;
  this can be used to copy and paste via ChangeName action (key `N')

LoadFreetype(font_name,face_index,attachment_name,[link|embed])
  load a FreeType font from file `font_name'; `face_index' is
  the index of face from the font file to use; `attachment_name'
  is the name of file to `attach' to the font; the last
  argument is whether to add a reference to the file or embed it
  into the PCB file. the default behaviour is to link, because
  embedding may restrict PCB file distribution terms; however,
  the user have to ensure that the font file will be available.
  the paths to the files are either absolute or relative to
  current PCB file location

LoadQCADFont(font_name,scale,line_width)
  load a QCAD font from file `font_name'; scale is multiplier
  to use for texts with scale equal to 100%; line_width is line
  width for such texts; the fonts are never embedded.

To make it possible to pick any glyphs from the font, even when
there is no Unicode character for it, escapes are introduced.
sequences like %FE; are interpreted as glyph index.

Revision history for this message
Ineiev (ineiev) wrote :
Revision history for this message
Ineiev (ineiev) wrote :

Updated version is at
http://repo.or.cz/w/geda-pcb/dti.git/shortlog/refs/heads/freetype

It fixes some bugs of initial version, uses polygons to render FreeType fonts,
increases the speed, makes some usability improvements.

Revision history for this message
Peter Clifton (pcjc2) wrote :

The output you get from freetype is very impressive. Regarding Pango though, I don't think it is as bad as you think regarding dependencies and bitmaps.

Pango can be built without cairo and fontconfig dependencies. That said, pango is pretty ubiqutous anyway, so ought not to cause a big problem as a dependency. (Nor should cairo if we wanted to use it).

It should be possible to write in a pango renderer which uses pango to layout the glyphs, and you provide your own routine for drawing the glyphs (as vectors, for example). This "ought" to be possible without recompiling a custom pango, as the render is just a GType subclass of the PangoRenderer class. That said.. I've never tried to do it!

gschem uses a custom pango renderer to interpret overbar markers in the text stream and render overbars, for example. In that case I didn't have to replace the glyph rendering routines, as I just called / used pango's cairo rendering routines.

Revision history for this message
Ineiev (ineiev) wrote :

The point is you can't rely on the system library for rendering PCB texts: if a line moves a half-pixel left,
it is nothing for schematics, but on a PCB it might result in a DRC violation; to avoid it you want
a particular version of the library. I include a FreeType2 library and build the application against it.

Probably Pango can be included, too; it's sources size is approximately the same as of FreeType2.
I think I'll try.

Revision history for this message
Colin D Bennett (colinb) wrote :

Ineiev, thanks for your work on this!! I haven't tried it myself yet, but I earnestly look forward to using TrueType fonts on my PCBs!

I am currently exporting text from Inkscape and using pstoedit to convert to pcb format with DJ Delorie's polystitch plugin to fix holes in the polygons. This is a lot of work and is really painful when I want to change some text on the board. It's not practical for general text, only for a couple of text items per board. It's much more readable than the default PCB font, especially at small sizes... but it's much more attractive at all sizes.

I hope this patch can be rolled into mainline pcb soon!

Traumflug (mah-jump-ing)
Changed in pcb:
importance: Undecided → Wishlist
Traumflug (mah-jump-ing)
Changed in geda-project:
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.