1 // Copyright (c) 2010-2017 The OTS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef OTS_CFF_TYPE2_CHARSTRING_H_ 6 #define OTS_CFF_TYPE2_CHARSTRING_H_ 7 8 #include "cff.h" 9 #include "ots.h" 10 11 #include <map> 12 #include <vector> 13 14 namespace ots { 15 16 const size_t kMaxCFF1ArgumentStack = 48; 17 const size_t kMaxCFF2ArgumentStack = 513; 18 19 // Validates all charstrings in |char_strings_index|. Charstring is a small 20 // language for font hinting defined in Adobe Technical Note #5177. 21 // http://www.adobe.com/devnet/font/pdfs/5177.Type2.pdf 22 // 23 // The validation will fail if one of the following conditions is met: 24 // 1. The code uses more than 48 values of argument stack. 25 // 2. The code uses deeply nested subroutine calls (more than 10 levels.) 26 // 3. The code passes invalid number of operands to an operator. 27 // 4. The code calls an undefined global or local subroutine. 28 // 5. The code uses one of the following operators that are unlikely used in 29 // an ordinary fonts, and could be dangerous: random, put, get, index, roll. 30 // 31 // Arguments: 32 // global_subrs_index: Global subroutines which could be called by a charstring 33 // in |char_strings_index|. 34 // fd_select: A map from glyph # to font #. 35 // local_subrs_per_font: A list of Local Subrs associated with FDArrays. Can be 36 // empty. 37 // local_subrs: A Local Subrs associated with Top DICT. Can be NULL. 38 // cff_table: A buffer which contains actual byte code of charstring, global 39 // subroutines and local subroutines. 40 bool ValidateCFFCharStrings( 41 OpenTypeCFF& cff, 42 const CFFIndex &global_subrs_index, 43 Buffer *cff_table); 44 45 // The list of Operators. See Appendix. A in Adobe Technical Note #5177. 46 // and https://docs.microsoft.com/en-us/typography/opentype/spec/cff2charstr 47 enum CharStringOperator { 48 kHStem = 1, 49 kVStem = 3, 50 kVMoveTo = 4, 51 kRLineTo = 5, 52 kHLineTo = 6, 53 kVLineTo = 7, 54 kRRCurveTo = 8, 55 kCallSubr = 10, 56 kReturn = 11, 57 kEndChar = 14, 58 kVSIndex = 15, 59 kBlend = 16, 60 kHStemHm = 18, 61 kHintMask = 19, 62 kCntrMask = 20, 63 kRMoveTo = 21, 64 kHMoveTo = 22, 65 kVStemHm = 23, 66 kRCurveLine = 24, 67 kRLineCurve = 25, 68 kVVCurveTo = 26, 69 kHHCurveTo = 27, 70 kCallGSubr = 29, 71 kVHCurveTo = 30, 72 kHVCurveTo = 31, 73 kDotSection = 12 << 8, 74 kAnd = (12 << 8) + 3, 75 kOr = (12 << 8) + 4, 76 kNot = (12 << 8) + 5, 77 kAbs = (12 << 8) + 9, 78 kAdd = (12 << 8) + 10, 79 kSub = (12 << 8) + 11, 80 kDiv = (12 << 8) + 12, 81 kNeg = (12 << 8) + 14, 82 kEq = (12 << 8) + 15, 83 kDrop = (12 << 8) + 18, 84 kPut = (12 << 8) + 20, 85 kGet = (12 << 8) + 21, 86 kIfElse = (12 << 8) + 22, 87 kRandom = (12 << 8) + 23, 88 kMul = (12 << 8) + 24, 89 kSqrt = (12 << 8) + 26, 90 kDup = (12 << 8) + 27, 91 kExch = (12 << 8) + 28, 92 kIndex = (12 << 8) + 29, 93 kRoll = (12 << 8) + 30, 94 kHFlex = (12 << 8) + 34, 95 kFlex = (12 << 8) + 35, 96 kHFlex1 = (12 << 8) + 36, 97 kFlex1 = (12 << 8) + 37, 98 // Operators that are undocumented, such as 'blend', will be rejected. 99 }; 100 101 } // namespace ots 102 103 #endif // OTS_CFF_TYPE2_CHARSTRING_H_ 104