/* * Copyright © 2018 Adobe Systems Incorporated. * * This is part of HarfBuzz, a text shaping library. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Adobe Author(s): Michiharu Ariza */ #include "hb-ot-cff1-table.hh" #include "hb-cff1-interp-cs.hh" using namespace CFF; /* SID to code */ static const uint8_t standard_encoding [] = { 0, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 188, 189, 191, 193, 194, 195, 196, 197, 198, 199, 200, 202, 203, 205, 206, 207, 208, 225, 227, 232, 233, 234, 235, 241, 245, 248, 249, 250, 251 }; /* SID to code */ static const uint8_t expert_encoding [] = { 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 45, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 201, 0, 0, 0, 0, 189, 0, 0, 188, 0, 0, 0, 0, 190, 202, 0, 0, 0, 0, 203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 60, 61, 62, 63, 65, 66, 67, 68, 69, 73, 76, 77, 78, 79, 82, 83, 84, 86, 89, 90, 91, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 166, 167, 168, 169, 170, 172, 175, 178, 179, 182, 183, 184, 191, 192, 193, 194, 195, 196, 197, 200, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; /* glyph ID to SID */ static const uint16_t expert_charset [] = { 0, 1, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 13, 14, 15, 99, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 27, 28, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 109, 110, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 158, 155, 163, 319, 320, 321, 322, 323, 324, 325, 326, 150, 164, 169, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378 }; /* glyph ID to SID */ static const uint16_t expert_subset_charset [] = { 0, 1, 231, 232, 235, 236, 237, 238, 13, 14, 15, 99, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 27, 28, 249, 250, 251, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 109, 110, 267, 268, 269, 270, 272, 300, 301, 302, 305, 314, 315, 158, 155, 163, 320, 321, 322, 323, 324, 325, 326, 150, 164, 169, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346 }; hb_codepoint_t OT::cff1::lookup_standard_encoding (hb_codepoint_t sid) { if (sid < ARRAY_LENGTH (standard_encoding)) return (hb_codepoint_t)standard_encoding[sid]; else return 0; } hb_codepoint_t OT::cff1::lookup_expert_encoding (hb_codepoint_t sid) { if (sid < ARRAY_LENGTH (expert_encoding)) return (hb_codepoint_t)expert_encoding[sid]; else return 0; } hb_codepoint_t OT::cff1::lookup_expert_charset (hb_codepoint_t glyph) { if (glyph < ARRAY_LENGTH (expert_charset)) return (hb_codepoint_t)expert_charset[glyph]; else return 0; } hb_codepoint_t OT::cff1::lookup_expert_subset_charset (hb_codepoint_t glyph) { if (glyph < ARRAY_LENGTH (expert_subset_charset)) return (hb_codepoint_t)expert_subset_charset[glyph]; else return 0; } struct ExtentsParam { inline void init (void) { path_open = false; min_x.set_int (0x7FFFFFFF); min_y.set_int (0x7FFFFFFF); max_x.set_int (-0x80000000); max_y.set_int (-0x80000000); } inline void start_path (void) { path_open = true; } inline void end_path (void) { path_open = false; } inline bool is_path_open (void) const { return path_open; } inline void update_bounds (const Point &pt) { if (pt.x < min_x) min_x = pt.x; if (pt.x > max_x) max_x = pt.x; if (pt.y < min_y) min_y = pt.y; if (pt.y > max_y) max_y = pt.y; } bool path_open; Number min_x; Number min_y; Number max_x; Number max_y; }; struct CFF1PathProcs_Extents : PathProcs { static inline void moveto (CFF1CSInterpEnv &env, ExtentsParam& param, const Point &pt) { param.end_path (); env.moveto (pt); } static inline void line (CFF1CSInterpEnv &env, ExtentsParam& param, const Point &pt1) { if (!param.is_path_open ()) { param.start_path (); param.update_bounds (env.get_pt ()); } env.moveto (pt1); param.update_bounds (env.get_pt ()); } static inline void curve (CFF1CSInterpEnv &env, ExtentsParam& param, const Point &pt1, const Point &pt2, const Point &pt3) { if (!param.is_path_open ()) { param.start_path (); param.update_bounds (env.get_pt ()); } /* include control points */ param.update_bounds (pt1); param.update_bounds (pt2); env.moveto (pt3); param.update_bounds (env.get_pt ()); } }; struct CFF1CSOpSet_Extents : CFF1CSOpSet {}; bool OT::cff1::accelerator_t::get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const { if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; unsigned int fd = fdSelect->get_fd (glyph); CFF1CSInterpreter interp; const ByteStr str = (*charStrings)[glyph]; interp.env.init (str, *this, fd); ExtentsParam param; param.init (); if (unlikely (!interp.interpret (param))) return false; if (param.min_x >= param.max_x) { extents->width = 0; extents->x_bearing = 0; } else { extents->x_bearing = (int32_t)param.min_x.floor (); extents->width = (int32_t)param.max_x.ceil () - extents->x_bearing; } if (param.min_y >= param.max_y) { extents->height = 0; extents->y_bearing = 0; } else { extents->y_bearing = (int32_t)param.max_y.ceil (); extents->height = (int32_t)param.min_y.floor () - extents->y_bearing; } return true; }