Showing
6 changed files
with
58 additions
and
57 deletions
@@ -6,7 +6,6 @@ analyzer: | @@ -6,7 +6,6 @@ analyzer: | ||
6 | missing_return: warning | 6 | missing_return: warning |
7 | public_member_api_docs: ignore | 7 | public_member_api_docs: ignore |
8 | todo: ignore | 8 | todo: ignore |
9 | - constant_identifier_names: ignore | ||
10 | avoid_print: ignore | 9 | avoid_print: ignore |
11 | no_leading_underscores_for_local_identifiers: ignore | 10 | no_leading_underscores_for_local_identifiers: ignore |
12 | 11 |
@@ -193,39 +193,37 @@ class PdfString extends PdfDataType { | @@ -193,39 +193,37 @@ class PdfString extends PdfDataType { | ||
193 | 193 | ||
194 | /// Produce a list of UTF-16BE encoded bytes. | 194 | /// Produce a list of UTF-16BE encoded bytes. |
195 | static List<int> _encodeUtf16be(String str) { | 195 | static List<int> _encodeUtf16be(String str) { |
196 | - const UNICODE_REPLACEMENT_CHARACTER_CODEPOINT = 0xfffd; | ||
197 | - const UNICODE_BYTE_ZERO_MASK = 0xff; | ||
198 | - const UNICODE_BYTE_ONE_MASK = 0xff00; | ||
199 | - const UNICODE_VALID_RANGE_MAX = 0x10ffff; | ||
200 | - const UNICODE_PLANE_ONE_MAX = 0xffff; | ||
201 | - const UNICODE_UTF16_RESERVED_LO = 0xd800; | ||
202 | - const UNICODE_UTF16_RESERVED_HI = 0xdfff; | ||
203 | - const UNICODE_UTF16_OFFSET = 0x10000; | ||
204 | - const UNICODE_UTF16_SURROGATE_UNIT_0_BASE = 0xd800; | ||
205 | - const UNICODE_UTF16_SURROGATE_UNIT_1_BASE = 0xdc00; | ||
206 | - const UNICODE_UTF16_HI_MASK = 0xffc00; | ||
207 | - const UNICODE_UTF16_LO_MASK = 0x3ff; | 196 | + const unicodeReplacementCharacterCodePoint = 0xfffd; |
197 | + const unicodeByteZeroMask = 0xff; | ||
198 | + const unicodeByteOneMask = 0xff00; | ||
199 | + const unicodeValidRangeMax = 0x10ffff; | ||
200 | + const unicodePlaneOneMax = 0xffff; | ||
201 | + const unicodeUtf16ReservedLo = 0xd800; | ||
202 | + const unicodeUtf16ReservedHi = 0xdfff; | ||
203 | + const unicodeUtf16Offset = 0x10000; | ||
204 | + const unicodeUtf16SurrogateUnit0Base = 0xd800; | ||
205 | + const unicodeUtf16SurrogateUnit1Base = 0xdc00; | ||
206 | + const unicodeUtf16HiMask = 0xffc00; | ||
207 | + const unicodeUtf16LoMask = 0x3ff; | ||
208 | 208 | ||
209 | final encoding = <int>[]; | 209 | final encoding = <int>[]; |
210 | 210 | ||
211 | void add(int unit) { | 211 | void add(int unit) { |
212 | - encoding.add((unit & UNICODE_BYTE_ONE_MASK) >> 8); | ||
213 | - encoding.add(unit & UNICODE_BYTE_ZERO_MASK); | 212 | + encoding.add((unit & unicodeByteOneMask) >> 8); |
213 | + encoding.add(unit & unicodeByteZeroMask); | ||
214 | } | 214 | } |
215 | 215 | ||
216 | for (final unit in str.codeUnits) { | 216 | for (final unit in str.codeUnits) { |
217 | - if ((unit >= 0 && unit < UNICODE_UTF16_RESERVED_LO) || | ||
218 | - (unit > UNICODE_UTF16_RESERVED_HI && unit <= UNICODE_PLANE_ONE_MAX)) { | 217 | + if ((unit >= 0 && unit < unicodeUtf16ReservedLo) || |
218 | + (unit > unicodeUtf16ReservedHi && unit <= unicodePlaneOneMax)) { | ||
219 | add(unit); | 219 | add(unit); |
220 | - } else if (unit > UNICODE_PLANE_ONE_MAX && | ||
221 | - unit <= UNICODE_VALID_RANGE_MAX) { | ||
222 | - final base = unit - UNICODE_UTF16_OFFSET; | ||
223 | - add(UNICODE_UTF16_SURROGATE_UNIT_0_BASE + | ||
224 | - ((base & UNICODE_UTF16_HI_MASK) >> 10)); | ||
225 | - add(UNICODE_UTF16_SURROGATE_UNIT_1_BASE + | ||
226 | - (base & UNICODE_UTF16_LO_MASK)); | 220 | + } else if (unit > unicodePlaneOneMax && unit <= unicodeValidRangeMax) { |
221 | + final base = unit - unicodeUtf16Offset; | ||
222 | + add(unicodeUtf16SurrogateUnit0Base + | ||
223 | + ((base & unicodeUtf16HiMask) >> 10)); | ||
224 | + add(unicodeUtf16SurrogateUnit1Base + (base & unicodeUtf16LoMask)); | ||
227 | } else { | 225 | } else { |
228 | - add(UNICODE_REPLACEMENT_CHARACTER_CODEPOINT); | 226 | + add(unicodeReplacementCharacterCodePoint); |
229 | } | 227 | } |
230 | } | 228 | } |
231 | return encoding; | 229 | return encoding; |
@@ -14,6 +14,8 @@ | @@ -14,6 +14,8 @@ | ||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | +// ignore_for_file: constant_identifier_names | ||
18 | + | ||
17 | import 'dart:convert'; | 19 | import 'dart:convert'; |
18 | import 'dart:math' as math; | 20 | import 'dart:math' as math; |
19 | import 'dart:typed_data'; | 21 | import 'dart:typed_data'; |
@@ -436,11 +438,11 @@ class TtfParser { | @@ -436,11 +438,11 @@ class TtfParser { | ||
436 | 438 | ||
437 | TtfGlyphInfo _readSimpleGlyph( | 439 | TtfGlyphInfo _readSimpleGlyph( |
438 | int glyph, int start, int offset, int numberOfContours) { | 440 | int glyph, int start, int offset, int numberOfContours) { |
439 | - const X_IS_BYTE = 2; | ||
440 | - const Y_IS_BYTE = 4; | ||
441 | - const REPEAT = 8; | ||
442 | - const X_DELTA = 16; | ||
443 | - const Y_DELTA = 32; | 441 | + const xIsByte = 2; |
442 | + const yIsByte = 4; | ||
443 | + const repeat = 8; | ||
444 | + const xDelta = 16; | ||
445 | + const yDelta = 32; | ||
444 | 446 | ||
445 | var numPoints = 1; | 447 | var numPoints = 1; |
446 | 448 | ||
@@ -449,7 +451,7 @@ class TtfParser { | @@ -449,7 +451,7 @@ class TtfParser { | ||
449 | offset += 2; | 451 | offset += 2; |
450 | } | 452 | } |
451 | 453 | ||
452 | - // skip over intructions | 454 | + // skip over instructions |
453 | offset += bytes.getUint16(offset) + 2; | 455 | offset += bytes.getUint16(offset) + 2; |
454 | 456 | ||
455 | if (numberOfContours == 0) { | 457 | if (numberOfContours == 0) { |
@@ -466,7 +468,7 @@ class TtfParser { | @@ -466,7 +468,7 @@ class TtfParser { | ||
466 | final flag = bytes.getUint8(offset++); | 468 | final flag = bytes.getUint8(offset++); |
467 | flags.add(flag); | 469 | flags.add(flag); |
468 | 470 | ||
469 | - if (flag & REPEAT != 0) { | 471 | + if (flag & repeat != 0) { |
470 | var repeatCount = bytes.getUint8(offset++); | 472 | var repeatCount = bytes.getUint8(offset++); |
471 | i += repeatCount; | 473 | i += repeatCount; |
472 | while (repeatCount-- > 0) { | 474 | while (repeatCount-- > 0) { |
@@ -475,8 +477,8 @@ class TtfParser { | @@ -475,8 +477,8 @@ class TtfParser { | ||
475 | } | 477 | } |
476 | } | 478 | } |
477 | 479 | ||
478 | - var byteFlag = X_IS_BYTE; | ||
479 | - var deltaFlag = X_DELTA; | 480 | + var byteFlag = xIsByte; |
481 | + var deltaFlag = xDelta; | ||
480 | for (var a = 0; a < 2; a++) { | 482 | for (var a = 0; a < 2; a++) { |
481 | for (var i = 0; i < numPoints; i++) { | 483 | for (var i = 0; i < numPoints; i++) { |
482 | final flag = flags[i]; | 484 | final flag = flags[i]; |
@@ -486,8 +488,8 @@ class TtfParser { | @@ -486,8 +488,8 @@ class TtfParser { | ||
486 | offset += 2; | 488 | offset += 2; |
487 | } | 489 | } |
488 | } | 490 | } |
489 | - byteFlag = Y_IS_BYTE; | ||
490 | - deltaFlag = Y_DELTA; | 491 | + byteFlag = yIsByte; |
492 | + deltaFlag = yDelta; | ||
491 | } | 493 | } |
492 | 494 | ||
493 | return TtfGlyphInfo( | 495 | return TtfGlyphInfo( |
@@ -498,31 +500,31 @@ class TtfParser { | @@ -498,31 +500,31 @@ class TtfParser { | ||
498 | } | 500 | } |
499 | 501 | ||
500 | TtfGlyphInfo _readCompoundGlyph(int glyph, int start, int offset) { | 502 | TtfGlyphInfo _readCompoundGlyph(int glyph, int start, int offset) { |
501 | - const ARG_1_AND_2_ARE_WORDS = 0x0001; | ||
502 | - const HAS_SCALE = 0x008; | ||
503 | - const MORE_COMPONENTS = 0x0020; | ||
504 | - const HAS_X_Y_SCALE = 0x0040; | ||
505 | - const HAS_TRANSFORMATION_MATRIX = 0x0080; | ||
506 | - const WE_HAVE_INSTRUCTIONS = 0x0100; | 503 | + const arg1And2AreWords = 0x0001; |
504 | + const hasScale = 0x008; | ||
505 | + const moreComponents = 0x0020; | ||
506 | + const hasXYScale = 0x0040; | ||
507 | + const hasTransformationMatrix = 0x0080; | ||
508 | + const weHaveInstructions = 0x0100; | ||
507 | 509 | ||
508 | final components = <int>[]; | 510 | final components = <int>[]; |
509 | var hasInstructions = false; | 511 | var hasInstructions = false; |
510 | - var flags = MORE_COMPONENTS; | 512 | + var flags = moreComponents; |
511 | 513 | ||
512 | - while (flags & MORE_COMPONENTS != 0) { | 514 | + while (flags & moreComponents != 0) { |
513 | flags = bytes.getUint16(offset); | 515 | flags = bytes.getUint16(offset); |
514 | final glyphIndex = bytes.getUint16(offset + 2); | 516 | final glyphIndex = bytes.getUint16(offset + 2); |
515 | - offset += (flags & ARG_1_AND_2_ARE_WORDS != 0) ? 8 : 6; | ||
516 | - if (flags & HAS_SCALE != 0) { | 517 | + offset += (flags & arg1And2AreWords != 0) ? 8 : 6; |
518 | + if (flags & hasScale != 0) { | ||
517 | offset += 2; | 519 | offset += 2; |
518 | - } else if (flags & HAS_X_Y_SCALE != 0) { | 520 | + } else if (flags & hasXYScale != 0) { |
519 | offset += 4; | 521 | offset += 4; |
520 | - } else if (flags & HAS_TRANSFORMATION_MATRIX != 0) { | 522 | + } else if (flags & hasTransformationMatrix != 0) { |
521 | offset += 8; | 523 | offset += 8; |
522 | } | 524 | } |
523 | 525 | ||
524 | components.add(glyphIndex); | 526 | components.add(glyphIndex); |
525 | - if (flags & WE_HAVE_INSTRUCTIONS != 0) { | 527 | + if (flags & weHaveInstructions != 0) { |
526 | assert(!hasInstructions); // Not already set | 528 | assert(!hasInstructions); // Not already set |
527 | hasInstructions = true; | 529 | hasInstructions = true; |
528 | } | 530 | } |
@@ -41,19 +41,19 @@ class TtfWriter { | @@ -41,19 +41,19 @@ class TtfWriter { | ||
41 | } | 41 | } |
42 | 42 | ||
43 | void _updateCompoundGlyph(TtfGlyphInfo glyph, Map<int, int?> compoundMap) { | 43 | void _updateCompoundGlyph(TtfGlyphInfo glyph, Map<int, int?> compoundMap) { |
44 | - const ARG_1_AND_2_ARE_WORDS = 1; | ||
45 | - const MORE_COMPONENTS = 32; | 44 | + const arg1And2AreWords = 1; |
45 | + const moreComponents = 32; | ||
46 | 46 | ||
47 | var offset = 10; | 47 | var offset = 10; |
48 | final bytes = glyph.data.buffer | 48 | final bytes = glyph.data.buffer |
49 | .asByteData(glyph.data.offsetInBytes, glyph.data.lengthInBytes); | 49 | .asByteData(glyph.data.offsetInBytes, glyph.data.lengthInBytes); |
50 | - var flags = MORE_COMPONENTS; | 50 | + var flags = moreComponents; |
51 | 51 | ||
52 | - while (flags & MORE_COMPONENTS != 0) { | 52 | + while (flags & moreComponents != 0) { |
53 | flags = bytes.getUint16(offset); | 53 | flags = bytes.getUint16(offset); |
54 | final glyphIndex = bytes.getUint16(offset + 2); | 54 | final glyphIndex = bytes.getUint16(offset + 2); |
55 | bytes.setUint16(offset + 2, compoundMap[glyphIndex]!); | 55 | bytes.setUint16(offset + 2, compoundMap[glyphIndex]!); |
56 | - offset += (flags & ARG_1_AND_2_ARE_WORDS != 0) ? 8 : 6; | 56 | + offset += (flags & arg1And2AreWords != 0) ? 8 : 6; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 |
@@ -66,13 +66,13 @@ void main() { | @@ -66,13 +66,13 @@ void main() { | ||
66 | final font2 = PdfTtfFont(pdf, data.buffer.asByteData()); | 66 | final font2 = PdfTtfFont(pdf, data.buffer.asByteData()); |
67 | const s = 'Hello World!'; | 67 | const s = 'Hello World!'; |
68 | final r = font2.stringMetrics(s); | 68 | final r = font2.stringMetrics(s); |
69 | - const FS = 20.0; | 69 | + const fs = 20.0; |
70 | g.setColor(const PdfColor(0, 1, 1)); | 70 | g.setColor(const PdfColor(0, 1, 1)); |
71 | g.drawRect( | 71 | g.drawRect( |
72 | - 50.0 + r.left * FS, 30.0 + r.top * FS, r.width * FS, r.height * FS); | 72 | + 50.0 + r.left * fs, 30.0 + r.top * fs, r.width * fs, r.height * fs); |
73 | g.fillPath(); | 73 | g.fillPath(); |
74 | g.setColor(const PdfColor(0.3, 0.3, 0.3)); | 74 | g.setColor(const PdfColor(0.3, 0.3, 0.3)); |
75 | - g.drawString(font2, FS, s, 50, 30); | 75 | + g.drawString(font2, fs, s, 50, 30); |
76 | 76 | ||
77 | g.setColor(const PdfColor(1, 0, 0)); | 77 | g.setColor(const PdfColor(1, 0, 0)); |
78 | g.drawString(font2, 20, 'Hé (Olà)', 50, 10); | 78 | g.drawString(font2, 20, 'Hé (Olà)', 50, 10); |
-
Please register or login to post a comment