
These points can be used for constraining the width of the text (or to the width of the text). The main parts of the commit are: * TtfFont is restructured to be able to return the aspect ratio for a given string. * This aspect ratio is written to the savefile, such that even if the font is missing, the sketch would still be solved correctly. * The two additional points are constrained via perpendicularly to the two main points (which form a v vector). The compatibility features are as follows: * When the font is missing in old files, 1:1 aspect ratio is used, which works for the replacement symbol anyhow. * When the two additional points are missing in old files, their would-be positions are calculated and they are moved there, avoiding 'jumping' of underconstrained sketches.
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
//-----------------------------------------------------------------------------
|
|
// Routines to read a TrueType font as vector outlines, and generate them
|
|
// as entities, since they're always representable as either lines or
|
|
// quadratic Bezier curves.
|
|
//
|
|
// Copyright 2016 whitequark, Peter Barfuss.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef __TTF_H
|
|
#define __TTF_H
|
|
|
|
class TtfFont {
|
|
public:
|
|
std::string fontFile;
|
|
std::string name;
|
|
FT_FaceRec_ *fontFace;
|
|
double capHeight;
|
|
|
|
std::string FontFileBaseName() const;
|
|
bool LoadFromFile(FT_LibraryRec_ *fontLibrary, bool nameOnly = true);
|
|
|
|
void PlotString(const std::string &str,
|
|
SBezierList *sbl, Vector origin, Vector u, Vector v);
|
|
double AspectRatio(const std::string &str);
|
|
};
|
|
|
|
class TtfFontList {
|
|
public:
|
|
FT_LibraryRec_ *fontLibrary;
|
|
bool loaded;
|
|
List<TtfFont> l;
|
|
|
|
TtfFontList();
|
|
~TtfFontList();
|
|
|
|
void LoadAll();
|
|
TtfFont *LoadFont(const std::string &font);
|
|
|
|
void PlotString(const std::string &font, const std::string &str,
|
|
SBezierList *sbl, Vector origin, Vector u, Vector v);
|
|
double AspectRatio(const std::string &font, const std::string &str);
|
|
};
|
|
|
|
#endif
|