1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 * @brief TrueType font creator
25 #ifndef INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
26 #define INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
32 struct TrueTypeCreator
;
34 /* TrueType data types */
40 /* A generic base class for all TrueType tables */
41 struct TrueTypeTable
{
42 sal_uInt32 tag
; /* table tag */
43 sal_uInt8
*rawdata
; /* raw data allocated by GetRawData_*() */
44 void *data
; /* table specific data */
47 /** Error codes for most functions */
49 TTCR_OK
, /**< no error */
50 TTCR_ZEROGLYPHS
, /**< At least one glyph should be defined */
51 TTCR_UNKNOWN
, /**< Unknown TrueType table */
52 TTCR_NONAMES
, /**< 'name' table does not contain any names */
53 TTCR_NAMETOOLONG
, /**< 'name' table is too long (string data > 64K) */
54 TTCR_POSTFORMAT
/**< unsupported format of a 'post' table */
58 * TrueTypeCreator constructor.
59 * Allocates all internal structures.
61 void TrueTypeCreatorNewEmpty(sal_uInt32 tag
, TrueTypeCreator
**_this
);
64 * Adds a TrueType table to the TrueType creator.
66 void AddTable(TrueTypeCreator
*_this
, TrueTypeTable
*table
);
69 * Removes a TrueType table from the TrueType creator if it is stored there.
70 * It also calls a TrueTypeTable destructor.
71 * Note: all generic tables (with tag 0) will be removed if this function is
72 * called with the second argument of 0.
73 * @return value of SFErrCodes type
75 void RemoveTable(TrueTypeCreator
*_this
, sal_uInt32 tag
);
78 * Writes a TrueType font generated by the TrueTypeCreator to a segment of
79 * memory that this method allocates. When it is not needed anymore the caller
80 * is supposed to call free() on it.
81 * @return value of SFErrCodes type
83 SFErrCodes
StreamToMemory(TrueTypeCreator
*_this
, sal_uInt8
**ptr
, sal_uInt32
*length
);
86 * Writes a TrueType font generated by the TrueTypeCreator to a file
87 * @return value of SFErrCodes type
89 SFErrCodes
StreamToFile(TrueTypeCreator
*_this
, const char* fname
);
92 * This function converts the data of a TrueType table to a raw array of bytes.
93 * It may allocates the memory for it and returns the size of the raw data in bytes.
94 * If memory is allocated it does not need to be freed by the caller of this function,
95 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor
100 int GetRawData(TrueTypeTable
*, sal_uInt8
**ptr
, sal_uInt32
*len
, sal_uInt32
*tag
);
104 * Creates a new raw TrueType table. The difference between this constructor and
105 * TrueTypeTableNew_tag constructors is that the latter create structured tables
106 * while this constructor just copies memory pointed to by ptr to its buffer
107 * and stores its length. This constructor is suitable for data that is not
108 * supposed to be processed in any way, just written to the resulting TTF file.
110 TrueTypeTable
*TrueTypeTableNew(sal_uInt32 tag
,
112 const sal_uInt8
* ptr
);
115 * Creates a new 'head' table for a TrueType font.
116 * Allocates memory for it. Since a lot of values in the 'head' table depend on the
117 * rest of the tables in the TrueType font this table should be the last one added
120 TrueTypeTable
*TrueTypeTableNew_head(sal_uInt32 fontRevision
,
122 sal_uInt16 unitsPerEm
,
123 const sal_uInt8
*created
,
125 sal_uInt16 lowestRecPPEM
,
126 sal_Int16 fontDirectionHint
);
129 * Creates a new 'hhea' table for a TrueType font.
130 * Allocates memory for it and stores it in the hhea pointer.
132 TrueTypeTable
*TrueTypeTableNew_hhea(sal_Int16 ascender
,
135 sal_Int16 caretSlopeRise
,
136 sal_Int16 caretSlopeRun
);
139 * Creates a new empty 'loca' table for a TrueType font.
141 * INTERNAL: gets called only from ProcessTables();
143 TrueTypeTable
*TrueTypeTableNew_loca();
146 * Creates a new 'maxp' table based on an existing maxp table.
147 * If maxp is 0, a new empty maxp table is created
148 * size specifies the size of existing maxp table for
149 * error-checking purposes
151 TrueTypeTable
*TrueTypeTableNew_maxp( const sal_uInt8
* maxp
, int size
);
154 * Creates a new empty 'glyf' table.
156 TrueTypeTable
*TrueTypeTableNew_glyf();
159 * Creates a new empty 'cmap' table.
161 TrueTypeTable
*TrueTypeTableNew_cmap();
164 * Creates a new 'name' table. If n != 0 the table gets populated by
165 * the Name Records stored in the nr array. This function allocates
166 * memory for its own copy of NameRecords, so nr array has to
167 * be explicitly deallocated when it is not needed.
169 TrueTypeTable
*TrueTypeTableNew_name(int n
, NameRecord
const *nr
);
172 * Creates a new 'post' table of one of the supported formats
174 TrueTypeTable
*TrueTypeTableNew_post(sal_Int32 format
,
175 sal_Int32 italicAngle
,
176 sal_Int16 underlinePosition
,
177 sal_Int16 underlineThickness
,
178 sal_uInt32 isFixedPitch
);
180 // Table manipulation functions
183 * Add a character/glyph pair to a cmap table
185 void cmapAdd(TrueTypeTable
*, sal_uInt32 id
, sal_uInt32 c
, sal_uInt32 g
);
188 * Add a glyph to a glyf table.
190 * @return glyphID of the glyph in the new font
192 * NOTE: This function does not duplicate GlyphData, so memory will be
193 * deallocated in the table destructor
195 sal_uInt32
glyfAdd(TrueTypeTable
*, GlyphData
*glyphdata
, AbstractTrueTypeFont
*fnt
);
198 * Query the number of glyphs currently stored in the 'glyf' table
201 sal_uInt32
glyfCount(const TrueTypeTable
*);
208 * Destructor for the TrueTypeTable object.
210 void TrueTypeTableDispose(void *);
213 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
215 void TrueTypeCreatorDispose(vcl::TrueTypeCreator
*_this
);
218 #endif // INCLUDED_VCL_SOURCE_FONTSUBSET_TTCR_HXX
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */