xref: /aoo41x/main/vcl/source/fontsubset/ttcr.hxx (revision 0d63794c)
1*0d63794cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0d63794cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0d63794cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0d63794cSAndrew Rist  * distributed with this work for additional information
6*0d63794cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0d63794cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0d63794cSAndrew Rist  * "License"); you may not use this file except in compliance
9*0d63794cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0d63794cSAndrew Rist  *
11*0d63794cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0d63794cSAndrew Rist  *
13*0d63794cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0d63794cSAndrew Rist  * software distributed under the License is distributed on an
15*0d63794cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0d63794cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*0d63794cSAndrew Rist  * specific language governing permissions and limitations
18*0d63794cSAndrew Rist  * under the License.
19*0d63794cSAndrew Rist  *
20*0d63794cSAndrew Rist  *************************************************************/
21*0d63794cSAndrew Rist 
22*0d63794cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /**
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  * @file ttcr.h
27cdf0e10cSrcweir  * @brief TrueType font creator
28cdf0e10cSrcweir  * @author Alexander Gelfenbain
29cdf0e10cSrcweir  */
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef __TTCR_H
32cdf0e10cSrcweir #define __TTCR_H
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "sft.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace vcl
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     typedef struct _TrueTypeCreator TrueTypeCreator;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /* TrueType data types */
41cdf0e10cSrcweir     typedef struct {
42cdf0e10cSrcweir         sal_uInt16 aw;
43cdf0e10cSrcweir         sal_Int16  lsb;
44cdf0e10cSrcweir     } longHorMetrics;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /* A generic base class for all TrueType tables */
47cdf0e10cSrcweir     struct TrueTypeTable {
48cdf0e10cSrcweir         sal_uInt32  tag;                         /* table tag                                                */
49cdf0e10cSrcweir         sal_uInt8   *rawdata;                    /* raw data allocated by GetRawData_*()                     */
50cdf0e10cSrcweir         void        *data;                       /* table specific data                                      */
51cdf0e10cSrcweir     };
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /** Error codes for most functions */
54cdf0e10cSrcweir     enum TTCRErrCodes {
55cdf0e10cSrcweir         TTCR_OK = 0,                        /**< no error                                               */
56cdf0e10cSrcweir         TTCR_ZEROGLYPHS = 1,                /**< At least one glyph should be defined                   */
57cdf0e10cSrcweir         TTCR_UNKNOWN = 2,                   /**< Unknown TrueType table                                 */
58cdf0e10cSrcweir         TTCR_GLYPHSEQ = 3,                  /**< Glyph IDs are not sequential in the glyf table         */
59cdf0e10cSrcweir         TTCR_NONAMES = 4,                   /**< 'name' table does not contain any names                */
60cdf0e10cSrcweir         TTCR_NAMETOOLONG = 5,               /**< 'name' table is too long (string data > 64K)           */
61cdf0e10cSrcweir         TTCR_POSTFORMAT = 6                 /**< unsupported format of a 'post' table                   */
62cdf0e10cSrcweir     };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir /* ============================================================================
65cdf0e10cSrcweir  *
66cdf0e10cSrcweir  * TrueTypeCreator methods
67cdf0e10cSrcweir  *
68cdf0e10cSrcweir  * ============================================================================ */
69cdf0e10cSrcweir 
70cdf0e10cSrcweir /**
71cdf0e10cSrcweir  * TrueTypeCreator constructor.
72cdf0e10cSrcweir  * Allocates all internal structures.
73cdf0e10cSrcweir  */
74cdf0e10cSrcweir     void TrueTypeCreatorNewEmpty(sal_uInt32 tag, TrueTypeCreator **_this);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir /**
77cdf0e10cSrcweir  * Adds a TrueType table to the TrueType creator.
78cdf0e10cSrcweir  * SF_TABLEFORMAT value.
79cdf0e10cSrcweir  * @return value of SFErrCodes type
80cdf0e10cSrcweir  */
81cdf0e10cSrcweir     int AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir /**
84cdf0e10cSrcweir  * Removes a TrueType table from the TrueType creator if it is stored there.
85cdf0e10cSrcweir  * It also calls a TrueTypeTable destructor.
86cdf0e10cSrcweir  * Note: all generic tables (with tag 0) will be removed if this function is
87cdf0e10cSrcweir  * called with the second argument of 0.
88cdf0e10cSrcweir  * @return value of SFErrCodes type
89cdf0e10cSrcweir  */
90cdf0e10cSrcweir     void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir /**
95cdf0e10cSrcweir  * Writes a TrueType font generated by the TrueTypeCreator to a segment of
96cdf0e10cSrcweir  * memory that this method allocates. When it is not needed anymore the caller
97cdf0e10cSrcweir  * is supposed to call free() on it.
98cdf0e10cSrcweir  * @return value of SFErrCodes type
99cdf0e10cSrcweir  */
100cdf0e10cSrcweir     int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir /**
103cdf0e10cSrcweir  * Writes a TrueType font  generated by the TrueTypeCreator to a file
104cdf0e10cSrcweir  * @return value of SFErrCodes type
105cdf0e10cSrcweir  */
106cdf0e10cSrcweir     int StreamToFile(TrueTypeCreator *_this, const char* fname);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir /* ============================================================================
110cdf0e10cSrcweir  *
111cdf0e10cSrcweir  * TrueTypeTable methods
112cdf0e10cSrcweir  *
113cdf0e10cSrcweir  * ============================================================================ */
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir /**
117cdf0e10cSrcweir  * This function converts the data of a TrueType table to a raw array of bytes.
118cdf0e10cSrcweir  * It may allocates the memory for it and returns the size of the raw data in bytes.
119cdf0e10cSrcweir  * If memory is allocated it does not need to be freed by the caller of this function,
120cdf0e10cSrcweir  * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor
121cdf0e10cSrcweir  * @return TTCRErrCode
122cdf0e10cSrcweir  *
123cdf0e10cSrcweir  */
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     int GetRawData(TrueTypeTable *, sal_uInt8 **ptr, sal_uInt32 *len, sal_uInt32 *tag);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir /**
128cdf0e10cSrcweir  *
129cdf0e10cSrcweir  * Creates a new raw TrueType table. The difference between this constructor and
130cdf0e10cSrcweir  * TrueTypeTableNew_tag constructors is that the latter create structured tables
131cdf0e10cSrcweir  * while this constructor just copies memory pointed to by ptr to its buffer
132cdf0e10cSrcweir  * and stores its length. This constructor is suitable for data that is not
133cdf0e10cSrcweir  * supposed to be processed in any way, just written to the resulting TTF file.
134cdf0e10cSrcweir  */
135cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew(sal_uInt32 tag,
136cdf0e10cSrcweir                                     sal_uInt32 nbytes,
137cdf0e10cSrcweir                                     const sal_uInt8* ptr);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /**
140cdf0e10cSrcweir  * Creates a new 'head' table for a TrueType font.
141cdf0e10cSrcweir  * Allocates memory for it. Since a lot of values in the 'head' table depend on the
142cdf0e10cSrcweir  * rest of the tables in the TrueType font this table should be the last one added
143cdf0e10cSrcweir  * to the font.
144cdf0e10cSrcweir  */
145cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_head(sal_uInt32 fontRevision,
146cdf0e10cSrcweir                                          sal_uInt16 flags,
147cdf0e10cSrcweir                                          sal_uInt16 unitsPerEm,
148cdf0e10cSrcweir                                          const sal_uInt8  *created,
149cdf0e10cSrcweir                                          sal_uInt16 macStyle,
150cdf0e10cSrcweir                                          sal_uInt16 lowestRecPPEM,
151cdf0e10cSrcweir                                          sal_Int16  fontDirectionHint);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir /**
154cdf0e10cSrcweir  * Creates a new 'hhea' table for a TrueType font.
155cdf0e10cSrcweir  * Allocates memory for it and stores it in the hhea pointer.
156cdf0e10cSrcweir  */
157cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_hhea(sal_Int16  ascender,
158cdf0e10cSrcweir                                          sal_Int16  descender,
159cdf0e10cSrcweir                                          sal_Int16  linegap,
160cdf0e10cSrcweir                                          sal_Int16  caretSlopeRise,
161cdf0e10cSrcweir                                          sal_Int16  caretSlopeRun);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir /**
164cdf0e10cSrcweir  * Creates a new empty 'loca' table for a TrueType font.
165cdf0e10cSrcweir  *
166cdf0e10cSrcweir  * INTERNAL: gets called only from ProcessTables();
167cdf0e10cSrcweir  */
168cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_loca(void);
169cdf0e10cSrcweir 
170cdf0e10cSrcweir /**
171cdf0e10cSrcweir  * Creates a new 'maxp' table based on an existing maxp table.
172cdf0e10cSrcweir  * If maxp is 0, a new empty maxp table is created
173cdf0e10cSrcweir  * size specifies the size of existing maxp table for
174cdf0e10cSrcweir  * error-checking purposes
175cdf0e10cSrcweir  */
176cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_maxp( const sal_uInt8* maxp, int size);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir /**
179cdf0e10cSrcweir  * Creates a new empty 'glyf' table.
180cdf0e10cSrcweir  */
181cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_glyf(void);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir /**
184cdf0e10cSrcweir  * Creates a new empty 'cmap' table.
185cdf0e10cSrcweir  */
186cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_cmap(void);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir /**
189cdf0e10cSrcweir  * Creates a new 'name' table. If n != 0 the table gets populated by
190cdf0e10cSrcweir  * the Name Records stored in the nr array. This function allocates
191cdf0e10cSrcweir  * memory for its own copy of NameRecords, so nr array has to
192cdf0e10cSrcweir  * be explicitly deallocated when it is not needed.
193cdf0e10cSrcweir  */
194cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir /**
197cdf0e10cSrcweir  * Creates a new 'post' table of one of the supported formats
198cdf0e10cSrcweir  */
199cdf0e10cSrcweir     TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format,
200cdf0e10cSrcweir                                          sal_uInt32 italicAngle,
201cdf0e10cSrcweir                                          sal_Int16 underlinePosition,
202cdf0e10cSrcweir                                          sal_Int16 underlineThickness,
203cdf0e10cSrcweir                                          sal_uInt32 isFixedPitch);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 
206cdf0e10cSrcweir /*------------------------------------------------------------------------------
207cdf0e10cSrcweir  *
208cdf0e10cSrcweir  *  Table manipulation functions
209cdf0e10cSrcweir  *
210cdf0e10cSrcweir  *------------------------------------------------------------------------------*/
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
213cdf0e10cSrcweir /**
214cdf0e10cSrcweir  * Add a character/glyph pair to a cmap table
215cdf0e10cSrcweir  */
216cdf0e10cSrcweir     void cmapAdd(TrueTypeTable *, sal_uInt32 id, sal_uInt32 c, sal_uInt32 g);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir /**
219cdf0e10cSrcweir  * Add a glyph to a glyf table.
220cdf0e10cSrcweir  *
221cdf0e10cSrcweir  * @return glyphID of the glyph in the new font
222cdf0e10cSrcweir  *
223cdf0e10cSrcweir  * NOTE: This function does not duplicate GlyphData, so memory will be
224cdf0e10cSrcweir  * deallocated in the table destructor
225cdf0e10cSrcweir  */
226cdf0e10cSrcweir     sal_uInt32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt);
227cdf0e10cSrcweir 
228cdf0e10cSrcweir /**
229cdf0e10cSrcweir  * Query the number of glyphs currently stored in the 'glyf' table
230cdf0e10cSrcweir  *
231cdf0e10cSrcweir  */
232cdf0e10cSrcweir     sal_uInt32 glyfCount(const TrueTypeTable *);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir /**
235cdf0e10cSrcweir  * Add a Name Record to a name table.
236cdf0e10cSrcweir  * NOTE: This function duplicates NameRecord, so the argument
237cdf0e10cSrcweir  * has to be deallocated by the caller (unlike glyfAdd)
238cdf0e10cSrcweir  */
239cdf0e10cSrcweir     void nameAdd(TrueTypeTable *, NameRecord *nr);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir } // namespace
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir extern "C"
245cdf0e10cSrcweir {
246cdf0e10cSrcweir /**
247cdf0e10cSrcweir  * Destructor for the TrueTypeTable object.
248cdf0e10cSrcweir  */
249cdf0e10cSrcweir  void TrueTypeTableDispose(vcl::TrueTypeTable *);
250cdf0e10cSrcweir 
251cdf0e10cSrcweir /**
252cdf0e10cSrcweir  * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
253cdf0e10cSrcweir  */
254cdf0e10cSrcweir  void TrueTypeCreatorDispose(vcl::TrueTypeCreator *_this);
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir #endif /* __TTCR_H */
258