blob: 3a019ef7821efacd0dc20b976a4e0ca4199c3824 [file] [log] [blame]
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -04001/*
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -04003 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020027#ifndef HB_OT_MAXP_TABLE_HH
28#define HB_OT_MAXP_TABLE_HH
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040029
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070030#include "hb-open-type.hh"
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040031
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040032namespace OT {
33
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040034
35/*
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +043036 * maxp -- Maximum Profile
37 * https://docs.microsoft.com/en-us/typography/opentype/spec/maxp
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040038 */
39
40#define HB_OT_TAG_maxp HB_TAG('m','a','x','p')
41
Garret Riegera76344d2018-02-27 14:11:36 -080042struct maxpV1Tail
43{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033044 bool sanitize (hb_sanitize_context_t *c) const
Garret Riegera76344d2018-02-27 14:11:36 -080045 {
46 TRACE_SANITIZE (this);
47 return_trace (c->check_struct (this));
48 }
49
Garret Riegerb26db482018-02-27 14:14:05 -080050 HBUINT16 maxPoints; /* Maximum points in a non-composite glyph. */
51 HBUINT16 maxContours; /* Maximum contours in a non-composite glyph. */
52 HBUINT16 maxCompositePoints; /* Maximum points in a composite glyph. */
Garret Riegera76344d2018-02-27 14:11:36 -080053 HBUINT16 maxCompositeContours; /* Maximum contours in a composite glyph. */
Garret Riegerb26db482018-02-27 14:14:05 -080054 HBUINT16 maxZones; /* 1 if instructions do not use the twilight zone (Z0),
Garret Rieger921b65c2018-02-27 14:37:18 -080055 * or 2 if instructions do use Z0; should be set to 2 in
56 * most cases. */
Garret Riegerb26db482018-02-27 14:14:05 -080057 HBUINT16 maxTwilightPoints; /* Maximum points used in Z0. */
58 HBUINT16 maxStorage; /* Number of Storage Area locations. */
59 HBUINT16 maxFunctionDefs; /* Number of FDEFs, equal to the highest function number + 1. */
60 HBUINT16 maxInstructionDefs; /* Number of IDEFs. */
61 HBUINT16 maxStackElements; /* Maximum stack depth. (This includes Font and CVT
Garret Rieger921b65c2018-02-27 14:37:18 -080062 * Programs, as well as the instructions for each glyph.) */
Garret Riegera76344d2018-02-27 14:11:36 -080063 HBUINT16 maxSizeOfInstructions; /* Maximum byte count for glyph instructions. */
64 HBUINT16 maxComponentElements; /* Maximum number of components referenced at
Garret Rieger921b65c2018-02-27 14:37:18 -080065 * "top level" for any composite glyph. */
Garret Riegerb26db482018-02-27 14:14:05 -080066 HBUINT16 maxComponentDepth; /* Maximum levels of recursion; 1 for simple components. */
Garret Rieger921b65c2018-02-27 14:37:18 -080067 public:
Garret Riegera76344d2018-02-27 14:11:36 -080068 DEFINE_SIZE_STATIC (26);
69};
70
71
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040072struct maxp
73{
Behdad Esfahbodef006542019-01-22 12:08:57 +010074 static constexpr hb_tag_t tableTag = HB_OT_TAG_maxp;
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040075
Ebrahim Byagowie4120082018-12-17 21:31:01 +033076 unsigned int get_num_glyphs () const { return numGlyphs; }
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040077
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033078 void set_num_glyphs (unsigned int count)
Garret Rieger83e1ef92018-02-12 11:22:32 -080079 {
Behdad Esfahbodb986c6a2019-03-29 20:17:46 -070080 numGlyphs = count;
Garret Rieger83e1ef92018-02-12 11:22:32 -080081 }
82
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033083 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +030084 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -050085 TRACE_SANITIZE (this);
Garret Riegera76344d2018-02-27 14:11:36 -080086 if (unlikely (!c->check_struct (this)))
87 return_trace (false);
88
89 if (version.major == 1)
90 {
91 const maxpV1Tail &v1 = StructAfter<maxpV1Tail> (*this);
Behdad Esfahbode1552af2018-10-30 21:09:05 -070092 return_trace (v1.sanitize (c));
Garret Riegera76344d2018-02-27 14:11:36 -080093 }
94 return_trace (likely (version.major == 0 && version.minor == 0x5000u));
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -040095 }
96
Qunxin Liudb938472019-06-04 10:30:53 -070097 bool subset (hb_subset_context_t *c) const
Garret Riegerdf6d7802018-02-12 17:56:17 -080098 {
Qunxin Liudb938472019-06-04 10:30:53 -070099 TRACE_SUBSET (this);
100 maxp *maxp_prime = c->serializer->embed (this);
101 if (unlikely (!maxp_prime)) return_trace (false);
Garret Riegerdf6d7802018-02-12 17:56:17 -0800102
Qunxin Liudb938472019-06-04 10:30:53 -0700103 maxp_prime->numGlyphs = c->plan->num_output_glyphs ();
Garret Riegerf14d1b62018-02-27 13:49:00 -0800104 if (maxp_prime->version.major == 1)
105 {
Qunxin Liudb938472019-06-04 10:30:53 -0700106 const maxpV1Tail *src_v1 = &StructAfter<maxpV1Tail> (*this);
107 maxpV1Tail *dest_v1 = c->serializer->embed<maxpV1Tail> (src_v1);
108 if (unlikely (!dest_v1)) return_trace (false);
109
Garret Rieger46d4a5e2021-07-29 15:07:13 -0700110 if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430111 drop_hint_fields (dest_v1);
Garret Riegerf14d1b62018-02-27 13:49:00 -0800112 }
Qunxin Liudb938472019-06-04 10:30:53 -0700113
114 return_trace (true);
115 }
116
117 static void drop_hint_fields (maxpV1Tail* dest_v1)
118 {
119 dest_v1->maxZones = 1;
120 dest_v1->maxTwilightPoints = 0;
121 dest_v1->maxStorage = 0;
122 dest_v1->maxFunctionDefs = 0;
123 dest_v1->maxInstructionDefs = 0;
124 dest_v1->maxStackElements = 0;
125 dest_v1->maxSizeOfInstructions = 0;
Garret Riegerf14d1b62018-02-27 13:49:00 -0800126 }
127
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400128 protected:
Ebrahim Byagowi08428a12020-04-24 23:45:17 +0430129 FixedVersion<>version;/* Version of the maxp table (0.5 or 1.0),
130 * 0x00005000u or 0x00010000u. */
131 HBUINT16 numGlyphs;
132 /* The number of glyphs in the font. */
Behdad Esfahbod0e294c42019-09-06 16:54:27 -0400133/*maxpV1Tail v1Tail[HB_VAR_ARRAY]; */
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400134 public:
Garret Riegera76344d2018-02-27 14:11:36 -0800135 DEFINE_SIZE_STATIC (6);
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400136};
137
138
Behdad Esfahbod7d52e662012-11-16 18:49:54 -0800139} /* namespace OT */
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400140
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400141
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +0200142#endif /* HB_OT_MAXP_TABLE_HH */