summaryrefslogtreecommitdiffstats
path: root/scribus/fonts/ftface.h
blob: db534d61177dcbf620817ed9134c32b0d7af29b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/

#ifndef FT_FACE_H
#define FT_FACE_H

#include <QString>
#include <QMap>

#include "scribusapi.h"

#include "fonts/scface.h"

#include <ft2build.h>
#include FT_FREETYPE_H

#include "fpointarray.h"

FT_Error ftIOFunc( FT_Stream stream, unsigned long pos, unsigned char* buffer, unsigned long count);


/*! \brief Base Class FtFace provides an ScFace private implementation
     for Freetype based fonts. Subclasses are ScFace_ps and ScFace_ttf.

Below is the old docs for class Foi:

This is subclassed by a class to handle Type1 fonts, a class
to handle TrueType fonts, and potentially any other type that becomes appropriate in
the future.
Note the virtual destructor, needed to ensure that the correct destructor is called
for subclasses

The RealName field has been changed from a data member to a member function.
This is because the only place the PostScript real name of a font is required is
the printing code, so it's cheaper to extract this information only when it is
required, for just the used fonts, than for every one of potentially hundreds at
application startup!  This also allows for the fact that truetype fonts will require
a different method of extracting their names.

One implication of using a base class/subclass model for fonts:  It is no longer
possible to store the ScFace structures in a QMap.  This is because QMap allocates
its own structures, and copies the supplied data to them.  A QMap<QString,ScFace>
would demote all subclasses to ScFace classes, and hence break the polymorphism.
QDict can be used instead, with very little change to the rest of the code, since
it stores references to the data instead of copying the data.  With AutoDelete set
to true, it will automatically dispose of all data when its destructor is called,
so there are no extra cleaning-up chores to take care of.
*/
struct SCRIBUS_API FtFace : public ScFace::ScFaceData
{

	FtFace(QString fam, QString sty, QString variant, QString scname, 
		   QString psname, QString path, int face);
	
	FT_Face ftFace() const;

	virtual ~FtFace();
	
	// font metrics
	qreal ascent(qreal sz=1.0)    const { return m_ascent * sz; }
	qreal descent(qreal sz=1.0)   const { return m_descent * sz; }
	qreal xHeight(qreal sz=1.0)   const { return m_xHeight * sz; }
	qreal capHeight(qreal sz=1.0) const { return m_capHeight * sz; }
	qreal height(qreal sz=1.0)    const { return m_height * sz; }
	qreal strikeoutPos(qreal sz=1.0)    const { return m_strikeoutPos * sz; }
	qreal underlinePos(qreal sz=1.0)    const { return m_underlinePos * sz; }
	qreal strokeWidth(qreal /*sz*/)     const { return m_strokeWidth; }
	qreal maxAdvanceWidth(qreal sz=1.0) const { return m_maxAdvanceWidth * sz; }
	QString pdfAscentAsString()      const { return m_pdfAscent; }
	QString pdfDescentAsString()     const { return m_pdfDescender; }
	QString pdfCapHeightAsString()   const { return m_pdfCapHeight; }
	QString pdfFontBBoxAsString()    const { return m_pdfFontBBox; }
	QString ItalicAngleAsString()    const { return m_italicAngle; }
	
	
//FIXME	QMap<QString,QString> fontDictionary(qreal sz=1.0)      const;
	
	uint         char2CMap(QChar ch)                         const;

	virtual qreal       glyphKerning (uint gl1, uint gl2, qreal sz) const;
//	GlyphMetrics glyphBBox (uint gl,               qreal sz) const;

	void RawData   (QByteArray & bb)            const;
	bool glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const;
	void load      ()                           const;
	void unload    ()                           const;
	void loadGlyph (uint ch)                    const;

protected:
	mutable FT_Face m_face;
	
	static FT_Library library;

	mutable QString m_pdfAscent;
	mutable QString m_pdfCapHeight;
	mutable QString m_pdfDescender;
	mutable QString m_italicAngle;
	mutable QString m_pdfFontBBox;
	mutable QString StdVW;
	QString FontEnc;

	mutable int m_encoding;
	
	mutable qreal m_uniEM;
	mutable qreal m_ascent;
	mutable qreal m_descent;
	mutable qreal m_height;
	mutable qreal m_xHeight;
	mutable qreal m_capHeight;
	mutable qreal m_maxAdvanceWidth;
	mutable qreal m_underlinePos;
	mutable qreal m_strikeoutPos;
	mutable qreal m_strokeWidth;
	
};

#endif