Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2023-03-15 18:34:04 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a6808fc7d1d8634054d8a15b9826b68ca8eb883d
a6808fc7
1 parent
99e9e924
Rename some constants to camel case
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
57 deletions
pdf/analysis_options.yaml
pdf/lib/src/pdf/data_types.dart
pdf/lib/src/pdf/exif.dart
pdf/lib/src/pdf/font/ttf_parser.dart
pdf/lib/src/pdf/font/ttf_writer.dart
pdf/test/complex_test.dart
pdf/analysis_options.yaml
View file @
a6808fc
...
...
@@ -6,7 +6,6 @@ analyzer:
missing_return
:
warning
public_member_api_docs
:
ignore
todo
:
ignore
constant_identifier_names
:
ignore
avoid_print
:
ignore
no_leading_underscores_for_local_identifiers
:
ignore
...
...
pdf/lib/src/pdf/data_types.dart
View file @
a6808fc
...
...
@@ -193,39 +193,37 @@ class PdfString extends PdfDataType {
/// Produce a list of UTF-16BE encoded bytes.
static
List
<
int
>
_encodeUtf16be
(
String
str
)
{
const
UNICODE_REPLACEMENT_CHARACTER_CODEPOINT
=
0xfffd
;
const
UNICODE_BYTE_ZERO_MASK
=
0xff
;
const
UNICODE_BYTE_ONE_MASK
=
0xff00
;
const
UNICODE_VALID_RANGE_MAX
=
0x10ffff
;
const
UNICODE_PLANE_ONE_MAX
=
0xffff
;
const
UNICODE_UTF16_RESERVED_LO
=
0xd800
;
const
UNICODE_UTF16_RESERVED_HI
=
0xdfff
;
const
UNICODE_UTF16_OFFSET
=
0x10000
;
const
UNICODE_UTF16_SURROGATE_UNIT_0_BASE
=
0xd800
;
const
UNICODE_UTF16_SURROGATE_UNIT_1_BASE
=
0xdc00
;
const
UNICODE_UTF16_HI_MASK
=
0xffc00
;
const
UNICODE_UTF16_LO_MASK
=
0x3ff
;
const
unicodeReplacementCharacterCodePoint
=
0xfffd
;
const
unicodeByteZeroMask
=
0xff
;
const
unicodeByteOneMask
=
0xff00
;
const
unicodeValidRangeMax
=
0x10ffff
;
const
unicodePlaneOneMax
=
0xffff
;
const
unicodeUtf16ReservedLo
=
0xd800
;
const
unicodeUtf16ReservedHi
=
0xdfff
;
const
unicodeUtf16Offset
=
0x10000
;
const
unicodeUtf16SurrogateUnit0Base
=
0xd800
;
const
unicodeUtf16SurrogateUnit1Base
=
0xdc00
;
const
unicodeUtf16HiMask
=
0xffc00
;
const
unicodeUtf16LoMask
=
0x3ff
;
final
encoding
=
<
int
>[];
void
add
(
int
unit
)
{
encoding
.
add
((
unit
&
UNICODE_BYTE_ONE_MASK
)
>>
8
);
encoding
.
add
(
unit
&
UNICODE_BYTE_ZERO_MASK
);
encoding
.
add
((
unit
&
unicodeByteOneMask
)
>>
8
);
encoding
.
add
(
unit
&
unicodeByteZeroMask
);
}
for
(
final
unit
in
str
.
codeUnits
)
{
if
((
unit
>=
0
&&
unit
<
UNICODE_UTF16_RESERVED_LO
)
||
(
unit
>
UNICODE_UTF16_RESERVED_HI
&&
unit
<=
UNICODE_PLANE_ONE_MAX
))
{
if
((
unit
>=
0
&&
unit
<
unicodeUtf16ReservedLo
)
||
(
unit
>
unicodeUtf16ReservedHi
&&
unit
<=
unicodePlaneOneMax
))
{
add
(
unit
);
}
else
if
(
unit
>
UNICODE_PLANE_ONE_MAX
&&
unit
<=
UNICODE_VALID_RANGE_MAX
)
{
final
base
=
unit
-
UNICODE_UTF16_OFFSET
;
add
(
UNICODE_UTF16_SURROGATE_UNIT_0_BASE
+
((
base
&
UNICODE_UTF16_HI_MASK
)
>>
10
));
add
(
UNICODE_UTF16_SURROGATE_UNIT_1_BASE
+
(
base
&
UNICODE_UTF16_LO_MASK
));
}
else
if
(
unit
>
unicodePlaneOneMax
&&
unit
<=
unicodeValidRangeMax
)
{
final
base
=
unit
-
unicodeUtf16Offset
;
add
(
unicodeUtf16SurrogateUnit0Base
+
((
base
&
unicodeUtf16HiMask
)
>>
10
));
add
(
unicodeUtf16SurrogateUnit1Base
+
(
base
&
unicodeUtf16LoMask
));
}
else
{
add
(
UNICODE_REPLACEMENT_CHARACTER_CODEPOINT
);
add
(
unicodeReplacementCharacterCodePoint
);
}
}
return
encoding
;
...
...
pdf/lib/src/pdf/exif.dart
View file @
a6808fc
...
...
@@ -14,6 +14,8 @@
* limitations under the License.
*/
// ignore_for_file: constant_identifier_names
import
'dart:convert'
;
import
'dart:typed_data'
;
...
...
pdf/lib/src/pdf/font/ttf_parser.dart
View file @
a6808fc
...
...
@@ -14,6 +14,8 @@
* limitations under the License.
*/
// ignore_for_file: constant_identifier_names
import
'dart:convert'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
...
...
@@ -436,11 +438,11 @@ class TtfParser {
TtfGlyphInfo
_readSimpleGlyph
(
int
glyph
,
int
start
,
int
offset
,
int
numberOfContours
)
{
const
X_IS_BYTE
=
2
;
const
Y_IS_BYTE
=
4
;
const
REPEAT
=
8
;
const
X_DELTA
=
16
;
const
Y_DELTA
=
32
;
const
xIsByte
=
2
;
const
yIsByte
=
4
;
const
repeat
=
8
;
const
xDelta
=
16
;
const
yDelta
=
32
;
var
numPoints
=
1
;
...
...
@@ -449,7 +451,7 @@ class TtfParser {
offset
+=
2
;
}
// skip over intructions
// skip over in
s
tructions
offset
+=
bytes
.
getUint16
(
offset
)
+
2
;
if
(
numberOfContours
==
0
)
{
...
...
@@ -466,7 +468,7 @@ class TtfParser {
final
flag
=
bytes
.
getUint8
(
offset
++);
flags
.
add
(
flag
);
if
(
flag
&
REPEAT
!=
0
)
{
if
(
flag
&
repeat
!=
0
)
{
var
repeatCount
=
bytes
.
getUint8
(
offset
++);
i
+=
repeatCount
;
while
(
repeatCount
--
>
0
)
{
...
...
@@ -475,8 +477,8 @@ class TtfParser {
}
}
var
byteFlag
=
X_IS_BYTE
;
var
deltaFlag
=
X_DELTA
;
var
byteFlag
=
xIsByte
;
var
deltaFlag
=
xDelta
;
for
(
var
a
=
0
;
a
<
2
;
a
++)
{
for
(
var
i
=
0
;
i
<
numPoints
;
i
++)
{
final
flag
=
flags
[
i
];
...
...
@@ -486,8 +488,8 @@ class TtfParser {
offset
+=
2
;
}
}
byteFlag
=
Y_IS_BYTE
;
deltaFlag
=
Y_DELTA
;
byteFlag
=
yIsByte
;
deltaFlag
=
yDelta
;
}
return
TtfGlyphInfo
(
...
...
@@ -498,31 +500,31 @@ class TtfParser {
}
TtfGlyphInfo
_readCompoundGlyph
(
int
glyph
,
int
start
,
int
offset
)
{
const
ARG_1_AND_2_ARE_WORDS
=
0x0001
;
const
HAS_SCALE
=
0x008
;
const
MORE_COMPONENTS
=
0x0020
;
const
HAS_X_Y_SCALE
=
0x0040
;
const
HAS_TRANSFORMATION_MATRIX
=
0x0080
;
const
WE_HAVE_INSTRUCTIONS
=
0x0100
;
const
arg1And2AreWords
=
0x0001
;
const
hasScale
=
0x008
;
const
moreComponents
=
0x0020
;
const
hasXYScale
=
0x0040
;
const
hasTransformationMatrix
=
0x0080
;
const
weHaveInstructions
=
0x0100
;
final
components
=
<
int
>[];
var
hasInstructions
=
false
;
var
flags
=
MORE_COMPONENTS
;
var
flags
=
moreComponents
;
while
(
flags
&
MORE_COMPONENTS
!=
0
)
{
while
(
flags
&
moreComponents
!=
0
)
{
flags
=
bytes
.
getUint16
(
offset
);
final
glyphIndex
=
bytes
.
getUint16
(
offset
+
2
);
offset
+=
(
flags
&
ARG_1_AND_2_ARE_WORDS
!=
0
)
?
8
:
6
;
if
(
flags
&
HAS_SCALE
!=
0
)
{
offset
+=
(
flags
&
arg1And2AreWords
!=
0
)
?
8
:
6
;
if
(
flags
&
hasScale
!=
0
)
{
offset
+=
2
;
}
else
if
(
flags
&
HAS_X_Y_SCALE
!=
0
)
{
}
else
if
(
flags
&
hasXYScale
!=
0
)
{
offset
+=
4
;
}
else
if
(
flags
&
HAS_TRANSFORMATION_MATRIX
!=
0
)
{
}
else
if
(
flags
&
hasTransformationMatrix
!=
0
)
{
offset
+=
8
;
}
components
.
add
(
glyphIndex
);
if
(
flags
&
WE_HAVE_INSTRUCTIONS
!=
0
)
{
if
(
flags
&
weHaveInstructions
!=
0
)
{
assert
(!
hasInstructions
);
// Not already set
hasInstructions
=
true
;
}
...
...
pdf/lib/src/pdf/font/ttf_writer.dart
View file @
a6808fc
...
...
@@ -41,19 +41,19 @@ class TtfWriter {
}
void
_updateCompoundGlyph
(
TtfGlyphInfo
glyph
,
Map
<
int
,
int
?>
compoundMap
)
{
const
ARG_1_AND_2_ARE_WORDS
=
1
;
const
MORE_COMPONENTS
=
32
;
const
arg1And2AreWords
=
1
;
const
moreComponents
=
32
;
var
offset
=
10
;
final
bytes
=
glyph
.
data
.
buffer
.
asByteData
(
glyph
.
data
.
offsetInBytes
,
glyph
.
data
.
lengthInBytes
);
var
flags
=
MORE_COMPONENTS
;
var
flags
=
moreComponents
;
while
(
flags
&
MORE_COMPONENTS
!=
0
)
{
while
(
flags
&
moreComponents
!=
0
)
{
flags
=
bytes
.
getUint16
(
offset
);
final
glyphIndex
=
bytes
.
getUint16
(
offset
+
2
);
bytes
.
setUint16
(
offset
+
2
,
compoundMap
[
glyphIndex
]!);
offset
+=
(
flags
&
ARG_1_AND_2_ARE_WORDS
!=
0
)
?
8
:
6
;
offset
+=
(
flags
&
arg1And2AreWords
!=
0
)
?
8
:
6
;
}
}
...
...
pdf/test/complex_test.dart
View file @
a6808fc
...
...
@@ -66,13 +66,13 @@ void main() {
final
font2
=
PdfTtfFont
(
pdf
,
data
.
buffer
.
asByteData
());
const
s
=
'Hello World!'
;
final
r
=
font2
.
stringMetrics
(
s
);
const
FS
=
20.0
;
const
fs
=
20.0
;
g
.
setColor
(
const
PdfColor
(
0
,
1
,
1
));
g
.
drawRect
(
50.0
+
r
.
left
*
FS
,
30.0
+
r
.
top
*
FS
,
r
.
width
*
FS
,
r
.
height
*
FS
);
50.0
+
r
.
left
*
fs
,
30.0
+
r
.
top
*
fs
,
r
.
width
*
fs
,
r
.
height
*
fs
);
g
.
fillPath
();
g
.
setColor
(
const
PdfColor
(
0.3
,
0.3
,
0.3
));
g
.
drawString
(
font2
,
FS
,
s
,
50
,
30
);
g
.
drawString
(
font2
,
fs
,
s
,
50
,
30
);
g
.
setColor
(
const
PdfColor
(
1
,
0
,
0
));
g
.
drawString
(
font2
,
20
,
'Hé (Olà)'
,
50
,
10
);
...
...
Please
register
or
login
to post a comment