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-18 10:33:23 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7f83264cadf3a9a01302efd493b72b2f203bd749
7f83264c
1 parent
5469c148
Improve Documents conformity
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
194 additions
and
29 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/format/array.dart
pdf/lib/src/pdf/obj/font.dart
pdf/lib/src/pdf/obj/type1_font.dart
test/golden/type1.pdf
pdf/CHANGELOG.md
View file @
7f83264
...
...
@@ -12,6 +12,7 @@
-
Draw page content only if not empty
-
Fix Page Content
-
Reorganize data types
-
Improve Documents conformity
## 3.9.0
...
...
pdf/lib/src/pdf/format/array.dart
View file @
7f83264
...
...
@@ -33,11 +33,11 @@ class PdfArray<T extends PdfDataType> extends PdfDataType {
}
}
static
PdfArray
<
PdfIndirect
>
fromObjects
(
List
<
PdfObjectBase
>
objects
)
{
static
PdfArray
<
PdfIndirect
>
fromObjects
(
Iterable
<
PdfObjectBase
>
objects
)
{
return
PdfArray
(
objects
.
map
<
PdfIndirect
>((
e
)
=>
e
.
ref
()).
toList
());
}
static
PdfArray
<
PdfNum
>
fromNum
(
List
<
num
>
list
)
{
static
PdfArray
<
PdfNum
>
fromNum
(
Iterable
<
num
>
list
)
{
return
PdfArray
(
list
.
map
<
PdfNum
>((
num
e
)
=>
PdfNum
(
e
)).
toList
());
}
...
...
pdf/lib/src/pdf/obj/font.dart
View file @
7f83264
...
...
@@ -38,86 +38,222 @@ abstract class PdfFont extends PdfObjectDict {
/// Monospaced slab serif typeface.
factory
PdfFont
.
courier
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Courier'
,
0.910
,
-
0.220
,
const
<
double
>[]);
pdfDocument
,
fontName:
'Courier'
,
ascent:
0.910
,
descent:
-
0.220
,
fontBBox:
[-
23
,
-
250
,
715
,
805
],
capHeight:
562
,
stdHW:
84
,
stdVW:
106
,
isFixedPitch:
true
,
missingWidth:
600
,
);
}
/// Bold monospaced slab serif typeface.
factory
PdfFont
.
courierBold
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Courier-Bold'
,
0.910
,
-
0.220
,
const
<
double
>[]);
pdfDocument
,
fontName:
'Courier-Bold'
,
ascent:
0.910
,
descent:
-
0.220
,
fontBBox:
[-
113
,
-
250
,
749
,
801
],
capHeight:
562
,
stdHW:
51
,
stdVW:
51
,
isFixedPitch:
true
,
missingWidth:
600
,
);
}
/// Bold and Italic monospaced slab serif typeface.
factory
PdfFont
.
courierBoldOblique
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Courier-BoldOblique'
,
0.910
,
-
0.220
,
const
<
double
>[]);
pdfDocument
,
fontName:
'Courier-BoldOblique'
,
ascent:
0.910
,
descent:
-
0.220
,
fontBBox:
[-
57
,
-
250
,
869
,
801
],
capHeight:
562
,
italicAngle:
-
12
,
isFixedPitch:
true
,
stdHW:
84
,
stdVW:
106
,
missingWidth:
600
,
);
}
/// Italic monospaced slab serif typeface.
factory
PdfFont
.
courierOblique
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Courier-Oblique'
,
0.910
,
-
0.220
,
const
<
double
>[]);
pdfDocument
,
fontName:
'Courier-Oblique'
,
ascent:
0.910
,
descent:
-
0.220
,
fontBBox:
[-
27
,
-
250
,
849
,
805
],
capHeight:
562
,
isFixedPitch:
true
,
italicAngle:
-
12
,
stdHW:
51
,
stdVW:
51
,
missingWidth:
600
,
);
}
/// Neo-grotesque design sans-serif typeface
factory
PdfFont
.
helvetica
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Helvetica'
,
0.931
,
-
0.225
,
helveticaWidths
);
pdfDocument
,
fontName:
'Helvetica'
,
ascent:
0.931
,
descent:
-
0.225
,
widths:
helveticaWidths
,
fontBBox:
[-
166
,
-
225
,
1000
,
931
],
capHeight:
718
,
stdHW:
76
,
stdVW:
88
,
);
}
/// Bold Neo-grotesque design sans-serif typeface
factory
PdfFont
.
helveticaBold
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Helvetica-Bold'
,
0.962
,
-
0.228
,
helveticaBoldWidths
);
pdfDocument
,
fontName:
'Helvetica-Bold'
,
ascent:
0.962
,
descent:
-
0.228
,
widths:
helveticaBoldWidths
,
fontBBox:
[-
170
,
-
228
,
1003
,
962
],
capHeight:
718
,
stdHW:
118
,
stdVW:
140
,
);
}
/// Bold and Italic Neo-grotesque design sans-serif typeface
factory
PdfFont
.
helveticaBoldOblique
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Helvetica-BoldOblique'
,
0.962
,
-
0.228
,
helveticaBoldObliqueWidths
);
return
PdfType1Font
.
create
(
pdfDocument
,
fontName:
'Helvetica-BoldOblique'
,
ascent:
0.962
,
descent:
-
0.228
,
widths:
helveticaBoldObliqueWidths
,
italicAngle:
-
12
,
fontBBox:
[-
170
,
-
228
,
1114
,
962
],
capHeight:
718
,
stdHW:
118
,
stdVW:
140
,
);
}
/// Italic Neo-grotesque design sans-serif typeface
factory
PdfFont
.
helveticaOblique
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Helvetica-Oblique'
,
0.931
,
-
0.225
,
helveticaObliqueWidths
);
return
PdfType1Font
.
create
(
pdfDocument
,
fontName:
'Helvetica-Oblique'
,
ascent:
0.931
,
descent:
-
0.225
,
widths:
helveticaObliqueWidths
,
italicAngle:
-
12
,
fontBBox:
[-
170
,
-
225
,
1116
,
931
],
capHeight:
718
,
stdHW:
76
,
stdVW:
88
,
);
}
/// Serif typeface commissioned by the British newspaper The Times
factory
PdfFont
.
times
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Times-Roman'
,
0.898
,
-
0.218
,
timesWidths
);
pdfDocument
,
fontName:
'Times-Roman'
,
ascent:
0.898
,
descent:
-
0.218
,
widths:
timesWidths
,
fontBBox:
[-
168
,
-
218
,
1000
,
898
],
capHeight:
662
,
stdHW:
28
,
stdVW:
84
,
);
}
/// Bold serif typeface commissioned by the British newspaper The Times
factory
PdfFont
.
timesBold
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Times-Bold'
,
0.935
,
-
0.218
,
timesBoldWidths
);
pdfDocument
,
fontName:
'Times-Bold'
,
ascent:
0.935
,
descent:
-
0.218
,
widths:
timesBoldWidths
,
fontBBox:
[-
168
,
-
218
,
1000
,
935
],
capHeight:
676
,
stdHW:
44
,
stdVW:
139
,
);
}
/// Bold and Italic serif typeface commissioned by the British newspaper The Times
factory
PdfFont
.
timesBoldItalic
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Times-BoldItalic'
,
0.921
,
-
0.218
,
timesBoldItalicWidths
);
pdfDocument
,
fontName:
'Times-BoldItalic'
,
ascent:
0.921
,
descent:
-
0.218
,
widths:
timesBoldItalicWidths
,
italicAngle:
-
15
,
fontBBox:
[-
200
,
-
218
,
996
,
921
],
capHeight:
669
,
stdHW:
42
,
stdVW:
121
,
);
}
/// Italic serif typeface commissioned by the British newspaper The Times
factory
PdfFont
.
timesItalic
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Times-Italic'
,
0.883
,
-
0.217
,
timesItalicWidths
);
pdfDocument
,
fontName:
'Times-Italic'
,
ascent:
0.883
,
descent:
-
0.217
,
widths:
timesItalicWidths
,
italicAngle:
-
15.5
,
fontBBox:
[-
169
,
-
217
,
1010
,
883
],
capHeight:
653
,
stdHW:
32
,
stdVW:
76
,
);
}
/// Complete unaccented serif Greek alphabet (upper and lower case) and a
/// selection of commonly used mathematical symbols.
factory
PdfFont
.
symbol
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'Symbol'
,
1.010
,
-
0.293
,
symbolWidths
);
pdfDocument
,
fontName:
'Symbol'
,
ascent:
1.010
,
descent:
-
0.293
,
widths:
symbolWidths
,
fontBBox:
[-
180
,
-
293
,
1090
,
1010
],
capHeight:
653
,
stdHW:
92
,
stdVW:
85
,
);
}
/// Hermann Zapf ornament glyphs or spacers, often employed to create box frames
factory
PdfFont
.
zapfDingbats
(
PdfDocument
pdfDocument
)
{
return
PdfType1Font
.
create
(
pdfDocument
,
'ZapfDingbats'
,
0.820
,
-
0.143
,
zapfDingbatsWidths
);
pdfDocument
,
fontName:
'ZapfDingbats'
,
ascent:
0.820
,
descent:
-
0.143
,
widths:
zapfDingbatsWidths
,
fontBBox:
[-
1
,
-
143
,
981
,
820
],
capHeight:
653
,
stdHW:
28
,
stdVW:
90
,
);
}
static
const
String
_cannotDecodeMessage
=
...
...
pdf/lib/src/pdf/obj/type1_font.dart
View file @
7f83264
...
...
@@ -14,10 +14,12 @@
* limitations under the License.
*/
import
'../../priv.dart'
;
import
'../document.dart'
;
import
'../font/font_metrics.dart'
;
import
'../format/
nam
e.dart'
;
import
'../format/
object_bas
e.dart'
;
import
'font.dart'
;
import
'object_dict.dart'
;
import
'ttffont.dart'
;
/// Type 1 font object.
...
...
@@ -30,15 +32,48 @@ import 'ttffont.dart';
/// see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
class
PdfType1Font
extends
PdfFont
{
/// Constructs a [PdfTtfFont]
PdfType1Font
.
create
(
PdfDocument
pdfDocument
,
this
.
fontName
,
this
.
ascent
,
this
.
descent
,
this
.
widths
)
PdfType1Font
.
create
(
PdfDocument
pdfDocument
,
{
required
this
.
fontName
,
required
this
.
ascent
,
required
this
.
descent
,
required
List
<
int
>
fontBBox
,
double
italicAngle
=
0
,
required
int
capHeight
,
required
int
stdHW
,
required
int
stdVW
,
bool
isFixedPitch
=
false
,
int
?
missingWidth
,
this
.
widths
=
const
<
double
>[]})
:
assert
(()
{
// ignore: avoid_print
print
(
'
$fontName
has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management'
);
return
true
;
}()),
super
.
create
(
pdfDocument
,
subtype:
'/Type1'
);
super
.
create
(
pdfDocument
,
subtype:
'/Type1'
)
{
params
[
'/BaseFont'
]
=
PdfName
(
'/
$fontName
'
);
if
(
version
.
index
>=
PdfVersion
.
pdf_1_5
.
index
)
{
params
[
'/FirstChar'
]
=
const
PdfNum
(
0
);
params
[
'/LastChar'
]
=
const
PdfNum
(
256
);
params
[
'/Widths'
]
=
PdfArray
.
fromNum
(
widths
.
map
((
e
)
=>
e
*
1000
));
final
fontDescriptor
=
PdfObjectDict
(
pdfDocument
,
type:
'/FontDescriptor'
)
..
params
[
'/FontName'
]
=
PdfName
(
'/
$fontName
'
)
..
params
[
'/Flags'
]
=
PdfNum
(
32
+
(
isFixedPitch
?
1
:
0
))
..
params
[
'/FontBBox'
]
=
PdfArray
.
fromNum
(
fontBBox
)
..
params
[
'/Ascent'
]
=
PdfNum
((
ascent
*
1000
).
toInt
())
..
params
[
'/Descent'
]
=
PdfNum
((
descent
*
1000
).
toInt
())
..
params
[
'/ItalicAngle'
]
=
PdfNum
(
italicAngle
)
..
params
[
'/CapHeight'
]
=
PdfNum
(
capHeight
)
..
params
[
'/StemV'
]
=
PdfNum
(
stdVW
)
..
params
[
'/StemH'
]
=
PdfNum
(
stdHW
);
if
(
missingWidth
!=
null
)
{
fontDescriptor
.
params
[
'/MissingWidth'
]
=
PdfNum
(
missingWidth
);
}
params
[
'/FontDescriptor'
]
=
fontDescriptor
.
ref
();
}
}
@override
final
String
fontName
;
...
...
@@ -56,13 +91,6 @@ class PdfType1Font extends PdfFont {
final
List
<
double
>
widths
;
@override
void
prepare
()
{
super
.
prepare
();
params
[
'/BaseFont'
]
=
PdfName
(
'/
$fontName
'
);
}
@override
PdfFontMetrics
glyphMetrics
(
int
charCode
)
{
if
(!
isRuneSupported
(
charCode
))
{
throw
Exception
(
...
...
test/golden/type1.pdf
View file @
7f83264
No preview for this file type
Please
register
or
login
to post a comment