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
2021-09-13 20:54:19 -0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4607273e862ba81b415563c876629d2203ef83e1
4607273e
1 parent
8d133f3d
Prefere unicode FontName
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
14 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/ttf_parser.dart
pdf/lib/src/pdf/ttffont.dart
pdf/lib/src/widgets/font.dart
pdf/test/widget_theme_test.dart
pdf/CHANGELOG.md
View file @
4607273
...
...
@@ -4,6 +4,7 @@
-
Fix text justify with multiple paragraphs
-
Apply Flutter 2.5 coding style
-
Prefere unicode FontName
## 3.5.0
...
...
pdf/lib/src/pdf/ttf_parser.dart
View file @
4607273
...
...
@@ -22,6 +22,32 @@ import 'package:meta/meta.dart';
import
'font_metrics.dart'
;
enum
TtfParserName
{
copyright
,
fontFamily
,
fontSubfamily
,
uniqueID
,
fullName
,
version
,
postScriptName
,
trademark
,
manufacturer
,
designer
,
description
,
manufacturerURL
,
designerURL
,
license
,
licenseURL
,
reserved
,
preferredFamily
,
preferredSubfamily
,
compatibleFullName
,
sampleText
,
postScriptFindFontName
,
wwsFamily
,
wwsSubfamily
,
}
@immutable
class
TtfGlyphInfo
{
const
TtfGlyphInfo
(
this
.
index
,
this
.
data
,
this
.
compounds
);
...
...
@@ -71,7 +97,6 @@ class TtfParser {
assert
(
tableOffsets
.
containsKey
(
glyf_table
),
'Unable to find the `glyf` table. This file is not a supported TTF font'
);
_parseFontName
();
_parseCMap
();
_parseIndexes
();
_parseGlyphs
();
...
...
@@ -89,7 +114,7 @@ class TtfParser {
final
UnmodifiableByteDataView
bytes
;
final
Map
<
String
,
int
>
tableOffsets
=
<
String
,
int
>{};
final
Map
<
String
,
int
>
tableSize
=
<
String
,
int
>{};
String
?
_fontName
;
final
Map
<
int
,
int
>
charToGlyphIndexMap
=
<
int
,
int
>{};
final
List
<
int
>
glyphOffsets
=
<
int
>[];
final
Map
<
int
,
PdfFontMetrics
>
glyphInfoMap
=
<
int
,
PdfFontMetrics
>{};
...
...
@@ -115,42 +140,46 @@ class TtfParser {
int
get
numGlyphs
=>
bytes
.
getUint16
(
tableOffsets
[
maxp_table
]!
+
4
);
String
?
get
fontName
=>
_fontName
;
String
get
fontName
=>
getNameID
(
TtfParserName
.
postScriptName
)
??
hashCode
.
toString
();
bool
get
unicode
=>
bytes
.
getUint32
(
0
)
==
0x10000
;
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
void
_parseFontName
(
)
{
String
?
getNameID
(
TtfParserName
fontNameID
)
{
final
basePosition
=
tableOffsets
[
name_table
]!;
// final format = bytes.getUint16(basePosition);
final
count
=
bytes
.
getUint16
(
basePosition
+
2
);
final
stringOffset
=
bytes
.
getUint16
(
basePosition
+
4
);
var
pos
=
basePosition
+
6
;
String
?
_fontName
;
for
(
var
i
=
0
;
i
<
count
;
i
++)
{
final
platformID
=
bytes
.
getUint16
(
pos
);
final
nameID
=
bytes
.
getUint16
(
pos
+
6
);
final
length
=
bytes
.
getUint16
(
pos
+
8
);
final
offset
=
bytes
.
getUint16
(
pos
+
10
);
pos
+=
12
;
if
(
platformID
==
1
&&
nameID
==
6
)
{
if
(
platformID
==
1
&&
nameID
==
fontNameID
.
index
)
{
try
{
_fontName
=
utf8
.
decode
(
bytes
.
buffer
.
asUint8List
(
basePosition
+
stringOffset
+
offset
,
length
));
return
;
}
catch
(
a
)
{
print
(
'Error:
$platformID
$nameID
$a
'
);
}
}
if
(
platformID
==
3
&&
nameID
==
6
)
{
if
(
platformID
==
3
&&
nameID
==
fontNameID
.
index
)
{
try
{
_fontName
=
_decodeUtf16
(
bytes
.
buffer
return
_decodeUtf16
(
bytes
.
buffer
.
asUint8List
(
basePosition
+
stringOffset
+
offset
,
length
));
return
;
}
catch
(
a
)
{
print
(
'Error:
$platformID
$nameID
$a
'
);
}
}
}
_fontName
=
hashCode
.
toString
()
;
return
_fontName
;
}
void
_parseCMap
()
{
...
...
pdf/lib/src/pdf/ttffont.dart
View file @
4607273
...
...
@@ -55,7 +55,7 @@ class PdfTtfFont extends PdfFont {
final
TtfParser
font
;
@override
String
get
fontName
=>
font
.
fontName
!
;
String
get
fontName
=>
font
.
fontName
;
@override
double
get
ascent
=>
font
.
ascent
.
toDouble
()
/
font
.
unitsPerEm
;
...
...
pdf/lib/src/widgets/font.dart
View file @
4607273
...
...
@@ -82,7 +82,7 @@ class Font {
Type1Fonts
.
zapfDingbats
:
'ZapfDingbats'
};
String
?
get
fontName
=>
_type1Map
[
font
]
;
String
get
fontName
=>
_type1Map
[
font
]!
;
@protected
PdfFont
buildFont
(
PdfDocument
pdfDocument
)
{
...
...
@@ -153,7 +153,7 @@ class TtfFont extends Font {
}
@override
String
?
get
fontName
{
String
get
fontName
{
if
(
_pdfFont
!=
null
)
{
return
_pdfFont
!.
fontName
;
}
...
...
@@ -162,6 +162,18 @@ class TtfFont extends Font {
return
font
.
fontName
;
}
String
?
fontNameID
(
TtfParserName
nameID
)
{
final
pdfFont
=
_pdfFont
;
if
(
pdfFont
!=
null
)
{
if
(
pdfFont
is
PdfTtfFont
)
{
return
pdfFont
.
font
.
getNameID
(
nameID
);
}
}
final
font
=
TtfParser
(
data
);
return
font
.
getNameID
(
nameID
);
}
@override
String
toString
()
{
final
font
=
TtfParser
(
data
);
...
...
pdf/test/widget_theme_test.dart
View file @
4607273
...
...
@@ -58,7 +58,7 @@ void main() {
build:
(
Context
context
)
=>
ListView
(
children:
<
Widget
>[
Text
(
style
.
font
!.
fontName
!
,
style
.
font
!.
fontName
,
style:
style
,
),
],
...
...
Please
register
or
login
to post a comment