build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / fontsubset / ttcr.hxx
blobdd6c262fbce5ea40562a26df5d8af0123feb1024
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /**
22 * @file ttcr.hxx
23 * @brief TrueType font creator
24 * @author Alexander Gelfenbain
27 #ifndef INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
28 #define INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
30 #include "sft.hxx"
32 namespace vcl
34 struct TrueTypeCreator;
36 /* TrueType data types */
37 typedef struct {
38 sal_uInt16 aw;
39 sal_Int16 lsb;
40 } longHorMetrics;
42 /* A generic base class for all TrueType tables */
43 struct TrueTypeTable {
44 sal_uInt32 tag; /* table tag */
45 sal_uInt8 *rawdata; /* raw data allocated by GetRawData_*() */
46 void *data; /* table specific data */
49 /** Error codes for most functions */
50 enum TTCRErrCodes {
51 TTCR_OK = 0, /**< no error */
52 TTCR_ZEROGLYPHS = 1, /**< At least one glyph should be defined */
53 TTCR_UNKNOWN = 2, /**< Unknown TrueType table */
54 TTCR_GLYPHSEQ = 3, /**< Glyph IDs are not sequential in the glyf table */
55 TTCR_NONAMES = 4, /**< 'name' table does not contain any names */
56 TTCR_NAMETOOLONG = 5, /**< 'name' table is too long (string data > 64K) */
57 TTCR_POSTFORMAT = 6 /**< unsupported format of a 'post' table */
60 /**
61 * TrueTypeCreator constructor.
62 * Allocates all internal structures.
64 void TrueTypeCreatorNewEmpty(sal_uInt32 tag, TrueTypeCreator **_this);
66 /**
67 * Adds a TrueType table to the TrueType creator.
68 * SF_TABLEFORMAT value.
69 * @return value of SFErrCodes type
71 int AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
73 /**
74 * Removes a TrueType table from the TrueType creator if it is stored there.
75 * It also calls a TrueTypeTable destructor.
76 * Note: all generic tables (with tag 0) will be removed if this function is
77 * called with the second argument of 0.
78 * @return value of SFErrCodes type
80 void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag);
82 /**
83 * Writes a TrueType font generated by the TrueTypeCreator to a segment of
84 * memory that this method allocates. When it is not needed anymore the caller
85 * is supposed to call free() on it.
86 * @return value of SFErrCodes type
88 int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length);
90 /**
91 * Writes a TrueType font generated by the TrueTypeCreator to a file
92 * @return value of SFErrCodes type
94 int StreamToFile(TrueTypeCreator *_this, const char* fname);
96 /**
97 * This function converts the data of a TrueType table to a raw array of bytes.
98 * It may allocates the memory for it and returns the size of the raw data in bytes.
99 * If memory is allocated it does not need to be freed by the caller of this function,
100 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor
101 * @return TTCRErrCode
105 int GetRawData(TrueTypeTable *, sal_uInt8 **ptr, sal_uInt32 *len, sal_uInt32 *tag);
109 * Creates a new raw TrueType table. The difference between this constructor and
110 * TrueTypeTableNew_tag constructors is that the latter create structured tables
111 * while this constructor just copies memory pointed to by ptr to its buffer
112 * and stores its length. This constructor is suitable for data that is not
113 * supposed to be processed in any way, just written to the resulting TTF file.
115 TrueTypeTable *TrueTypeTableNew(sal_uInt32 tag,
116 sal_uInt32 nbytes,
117 const sal_uInt8* ptr);
120 * Creates a new 'head' table for a TrueType font.
121 * Allocates memory for it. Since a lot of values in the 'head' table depend on the
122 * rest of the tables in the TrueType font this table should be the last one added
123 * to the font.
125 TrueTypeTable *TrueTypeTableNew_head(sal_uInt32 fontRevision,
126 sal_uInt16 flags,
127 sal_uInt16 unitsPerEm,
128 const sal_uInt8 *created,
129 sal_uInt16 macStyle,
130 sal_uInt16 lowestRecPPEM,
131 sal_Int16 fontDirectionHint);
134 * Creates a new 'hhea' table for a TrueType font.
135 * Allocates memory for it and stores it in the hhea pointer.
137 TrueTypeTable *TrueTypeTableNew_hhea(sal_Int16 ascender,
138 sal_Int16 descender,
139 sal_Int16 linegap,
140 sal_Int16 caretSlopeRise,
141 sal_Int16 caretSlopeRun);
144 * Creates a new empty 'loca' table for a TrueType font.
146 * INTERNAL: gets called only from ProcessTables();
148 TrueTypeTable *TrueTypeTableNew_loca();
151 * Creates a new 'maxp' table based on an existing maxp table.
152 * If maxp is 0, a new empty maxp table is created
153 * size specifies the size of existing maxp table for
154 * error-checking purposes
156 TrueTypeTable *TrueTypeTableNew_maxp( const sal_uInt8* maxp, int size);
159 * Creates a new empty 'glyf' table.
161 TrueTypeTable *TrueTypeTableNew_glyf();
164 * Creates a new empty 'cmap' table.
166 TrueTypeTable *TrueTypeTableNew_cmap();
169 * Creates a new 'name' table. If n != 0 the table gets populated by
170 * the Name Records stored in the nr array. This function allocates
171 * memory for its own copy of NameRecords, so nr array has to
172 * be explicitly deallocated when it is not needed.
174 TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr);
177 * Creates a new 'post' table of one of the supported formats
179 TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format,
180 sal_uInt32 italicAngle,
181 sal_Int16 underlinePosition,
182 sal_Int16 underlineThickness,
183 sal_uInt32 isFixedPitch);
185 // Table manipulation functions
188 * Add a character/glyph pair to a cmap table
190 void cmapAdd(TrueTypeTable *, sal_uInt32 id, sal_uInt32 c, sal_uInt32 g);
193 * Add a glyph to a glyf table.
195 * @return glyphID of the glyph in the new font
197 * NOTE: This function does not duplicate GlyphData, so memory will be
198 * deallocated in the table destructor
200 sal_uInt32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt);
203 * Query the number of glyphs currently stored in the 'glyf' table
206 sal_uInt32 glyfCount(const TrueTypeTable *);
209 * Add a Name Record to a name table.
210 * NOTE: This function duplicates NameRecord, so the argument
211 * has to be deallocated by the caller (unlike glyfAdd)
213 void nameAdd(TrueTypeTable *, NameRecord *nr);
215 } // namespace
217 extern "C"
220 * Destructor for the TrueTypeTable object.
222 void TrueTypeTableDispose(void *);
225 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
227 void TrueTypeCreatorDispose(vcl::TrueTypeCreator *_this);
230 #endif // INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */