1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 * @brief TrueType font creator
32 * @author Alexander Gelfenbain
42 typedef struct _TrueTypeCreator TrueTypeCreator
;
44 /* TrueType data types */
50 /* A generic base class for all TrueType tables */
51 struct TrueTypeTable
{
52 sal_uInt32 tag
; /* table tag */
53 sal_uInt8
*rawdata
; /* raw data allocated by GetRawData_*() */
54 void *data
; /* table specific data */
57 /** Error codes for most functions */
59 TTCR_OK
= 0, /**< no error */
60 TTCR_ZEROGLYPHS
= 1, /**< At least one glyph should be defined */
61 TTCR_UNKNOWN
= 2, /**< Unknown TrueType table */
62 TTCR_GLYPHSEQ
= 3, /**< Glyph IDs are not sequential in the glyf table */
63 TTCR_NONAMES
= 4, /**< 'name' table does not contain any names */
64 TTCR_NAMETOOLONG
= 5, /**< 'name' table is too long (string data > 64K) */
65 TTCR_POSTFORMAT
= 6 /**< unsupported format of a 'post' table */
68 /* ============================================================================
70 * TrueTypeCreator methods
72 * ============================================================================ */
75 * TrueTypeCreator constructor.
76 * Allocates all internal structures.
78 void TrueTypeCreatorNewEmpty(sal_uInt32 tag
, TrueTypeCreator
**_this
);
81 * Adds a TrueType table to the TrueType creator.
82 * SF_TABLEFORMAT value.
83 * @return value of SFErrCodes type
85 int AddTable(TrueTypeCreator
*_this
, TrueTypeTable
*table
);
88 * Removes a TrueType table from the TrueType creator if it is stored there.
89 * It also calls a TrueTypeTable destructor.
90 * Note: all generic tables (with tag 0) will be removed if this function is
91 * called with the second argument of 0.
92 * @return value of SFErrCodes type
94 void RemoveTable(TrueTypeCreator
*_this
, sal_uInt32 tag
);
99 * Writes a TrueType font generated by the TrueTypeCreator to a segment of
100 * memory that this method allocates. When it is not needed anymore the caller
101 * is supposed to call free() on it.
102 * @return value of SFErrCodes type
104 int StreamToMemory(TrueTypeCreator
*_this
, sal_uInt8
**ptr
, sal_uInt32
*length
);
107 * Writes a TrueType font generated by the TrueTypeCreator to a file
108 * @return value of SFErrCodes type
110 int StreamToFile(TrueTypeCreator
*_this
, const char* fname
);
113 /* ============================================================================
115 * TrueTypeTable methods
117 * ============================================================================ */
121 * This function converts the data of a TrueType table to a raw array of bytes.
122 * It may allocates the memory for it and returns the size of the raw data in bytes.
123 * If memory is allocated it does not need to be freed by the caller of this function,
124 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor
125 * @return TTCRErrCode
129 int GetRawData(TrueTypeTable
*, sal_uInt8
**ptr
, sal_uInt32
*len
, sal_uInt32
*tag
);
133 * Creates a new raw TrueType table. The difference between this constructor and
134 * TrueTypeTableNew_tag constructors is that the latter create structured tables
135 * while this constructor just copies memory pointed to by ptr to its buffer
136 * and stores its length. This constructor is suitable for data that is not
137 * supposed to be processed in any way, just written to the resulting TTF file.
139 TrueTypeTable
*TrueTypeTableNew(sal_uInt32 tag
,
141 const sal_uInt8
* ptr
);
144 * Creates a new 'head' table for a TrueType font.
145 * Allocates memory for it. Since a lot of values in the 'head' table depend on the
146 * rest of the tables in the TrueType font this table should be the last one added
149 TrueTypeTable
*TrueTypeTableNew_head(sal_uInt32 fontRevision
,
151 sal_uInt16 unitsPerEm
,
152 const sal_uInt8
*created
,
154 sal_uInt16 lowestRecPPEM
,
155 sal_Int16 fontDirectionHint
);
158 * Creates a new 'hhea' table for a TrueType font.
159 * Allocates memory for it and stores it in the hhea pointer.
161 TrueTypeTable
*TrueTypeTableNew_hhea(sal_Int16 ascender
,
164 sal_Int16 caretSlopeRise
,
165 sal_Int16 caretSlopeRun
);
168 * Creates a new empty 'loca' table for a TrueType font.
170 * INTERNAL: gets called only from ProcessTables();
172 TrueTypeTable
*TrueTypeTableNew_loca(void);
175 * Creates a new 'maxp' table based on an existing maxp table.
176 * If maxp is 0, a new empty maxp table is created
177 * size specifies the size of existing maxp table for
178 * error-checking purposes
180 TrueTypeTable
*TrueTypeTableNew_maxp( const sal_uInt8
* maxp
, int size
);
183 * Creates a new empty 'glyf' table.
185 TrueTypeTable
*TrueTypeTableNew_glyf(void);
188 * Creates a new empty 'cmap' table.
190 TrueTypeTable
*TrueTypeTableNew_cmap(void);
193 * Creates a new 'name' table. If n != 0 the table gets populated by
194 * the Name Records stored in the nr array. This function allocates
195 * memory for its own copy of NameRecords, so nr array has to
196 * be explicitly deallocated when it is not needed.
198 TrueTypeTable
*TrueTypeTableNew_name(int n
, NameRecord
*nr
);
201 * Creates a new 'post' table of one of the supported formats
203 TrueTypeTable
*TrueTypeTableNew_post(sal_uInt32 format
,
204 sal_uInt32 italicAngle
,
205 sal_Int16 underlinePosition
,
206 sal_Int16 underlineThickness
,
207 sal_uInt32 isFixedPitch
);
210 /*------------------------------------------------------------------------------
212 * Table manipulation functions
214 *------------------------------------------------------------------------------*/
218 * Add a character/glyph pair to a cmap table
220 void cmapAdd(TrueTypeTable
*, sal_uInt32 id
, sal_uInt32 c
, sal_uInt32 g
);
223 * Add a glyph to a glyf table.
225 * @return glyphID of the glyph in the new font
227 * NOTE: This function does not duplicate GlyphData, so memory will be
228 * deallocated in the table destructor
230 sal_uInt32
glyfAdd(TrueTypeTable
*, GlyphData
*glyphdata
, TrueTypeFont
*fnt
);
233 * Query the number of glyphs currently stored in the 'glyf' table
236 sal_uInt32
glyfCount(const TrueTypeTable
*);
239 * Add a Name Record to a name table.
240 * NOTE: This function duplicates NameRecord, so the argument
241 * has to be deallocated by the caller (unlike glyfAdd)
243 void nameAdd(TrueTypeTable
*, NameRecord
*nr
);
251 * Destructor for the TrueTypeTable object.
253 void TrueTypeTableDispose(vcl::TrueTypeTable
*);
256 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
258 void TrueTypeCreatorDispose(vcl::TrueTypeCreator
*_this
);
261 #endif /* __TTCR_H */