blob: a2d9167c52c0ab7f283b277add7ba2f8a20b3c3a [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
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033097 bool subset (hb_subset_plan_t *plan) const
Garret Riegerdf6d7802018-02-12 17:56:17 -080098 {
Behdad Esfahbod36ed1632018-07-23 11:57:45 -070099 hb_blob_t *maxp_blob = hb_sanitize_context_t().reference_table<maxp> (plan->source);
Rod Sheeter2d6b1e22018-02-14 19:14:01 -0800100 hb_blob_t *maxp_prime_blob = hb_blob_copy_writable_or_fail (maxp_blob);
Garret Riegerdf6d7802018-02-12 17:56:17 -0800101 hb_blob_destroy (maxp_blob);
102
Rod Sheeter2d6b1e22018-02-14 19:14:01 -0800103 if (unlikely (!maxp_prime_blob)) {
Rod Sheeterfa877702018-02-14 14:16:25 -0800104 return false;
Garret Riegerdf6d7802018-02-12 17:56:17 -0800105 }
Behdad Esfahbod36ed1632018-07-23 11:57:45 -0700106 maxp *maxp_prime = (maxp *) hb_blob_get_data (maxp_prime_blob, nullptr);
Garret Riegerdf6d7802018-02-12 17:56:17 -0800107
Garret Rieger853b1f12019-01-28 16:50:56 -0800108 maxp_prime->set_num_glyphs (plan->num_output_glyphs ());
Garret Riegerf14d1b62018-02-27 13:49:00 -0800109 if (plan->drop_hints)
110 drop_hint_fields (plan, maxp_prime);
Garret Riegerdf6d7802018-02-12 17:56:17 -0800111
Garret Rieger251cc972018-05-30 12:23:51 -0700112 bool result = plan->add_table (HB_OT_TAG_maxp, maxp_prime_blob);
Garret Rieger3ab7d262018-02-14 15:48:57 -0800113 hb_blob_destroy (maxp_prime_blob);
114 return result;
Garret Riegerdf6d7802018-02-12 17:56:17 -0800115 }
116
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330117 static void drop_hint_fields (hb_subset_plan_t *plan HB_UNUSED, maxp *maxp_prime)
Garret Riegerf14d1b62018-02-27 13:49:00 -0800118 {
119 if (maxp_prime->version.major == 1)
120 {
Garret Rieger921b65c2018-02-27 14:37:18 -0800121 maxpV1Tail &v1 = StructAfter<maxpV1Tail> (*maxp_prime);
Behdad Esfahbodb986c6a2019-03-29 20:17:46 -0700122 v1.maxZones = 1;
123 v1.maxTwilightPoints = 0;
124 v1.maxStorage = 0;
125 v1.maxFunctionDefs = 0;
126 v1.maxInstructionDefs = 0;
127 v1.maxStackElements = 0;
128 v1.maxSizeOfInstructions = 0;
Garret Riegerf14d1b62018-02-27 13:49:00 -0800129 }
130 }
131
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400132 protected:
Behdad Esfahbod9a13ed42016-02-22 11:44:45 +0900133 FixedVersion<>version; /* Version of the maxp table (0.5 or 1.0),
Behdad Esfahbod76271002014-07-11 14:54:42 -0400134 * 0x00005000u or 0x00010000u. */
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100135 HBUINT16 numGlyphs; /* The number of glyphs in the font. */
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200136/*maxpV1Tail v1Tail[VAR]; */
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400137 public:
Garret Riegera76344d2018-02-27 14:11:36 -0800138 DEFINE_SIZE_STATIC (6);
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400139};
140
141
Behdad Esfahbod7d52e662012-11-16 18:49:54 -0800142} /* namespace OT */
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400143
Behdad Esfahbod6a4e7e12011-05-11 10:31:33 -0400144
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +0200145#endif /* HB_OT_MAXP_TABLE_HH */