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
2020-12-02 10:02:28 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c7403f6adcb2db6616e447687f9bbb0c20c5181e
c7403f6a
1 parent
d1baa36b
Add soft mask
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
4 deletions
pdf/CHANGELOG.md
pdf/lib/pdf.dart
pdf/lib/src/graphic_state.dart
pdf/lib/src/smask.dart
pdf/lib/src/xobject.dart
pdf/CHANGELOG.md
View file @
c7403f6
...
...
@@ -15,6 +15,7 @@
-
Automatically calculate Shape() bounding box
-
Improve gradient functions
-
Add blend mode
-
Add soft mask
## 1.12.0
...
...
pdf/lib/pdf.dart
View file @
c7403f6
...
...
@@ -37,5 +37,6 @@ export 'src/point.dart';
export
'src/rect.dart'
;
export
'src/shading.dart'
;
export
'src/signature.dart'
;
export
'src/smask.dart'
;
export
'src/ttf_parser.dart'
;
export
'src/ttffont.dart'
;
...
...
pdf/lib/src/graphic_state.dart
View file @
c7403f6
...
...
@@ -21,6 +21,8 @@ import 'package:meta/meta.dart';
import
'data_types.dart'
;
import
'document.dart'
;
import
'object.dart'
;
import
'smask.dart'
;
enum
PdfBlendMode
{
/// Selects the source colour, ignoring the backdrop
normal
,
...
...
@@ -81,7 +83,7 @@ enum PdfBlendMode {
@immutable
class
PdfGraphicState
{
/// Create a new graphic state
const
PdfGraphicState
({
this
.
opacity
,
this
.
blendMode
});
const
PdfGraphicState
({
this
.
opacity
,
this
.
blendMode
,
this
.
softMask
});
/// The opacity to apply to this graphic state
final
double
opacity
;
...
...
@@ -89,6 +91,8 @@ class PdfGraphicState {
/// The current blend mode to be used
final
PdfBlendMode
blendMode
;
final
PdfSoftMask
softMask
;
PdfDict
output
()
{
final
params
=
PdfDict
();
...
...
@@ -99,11 +103,14 @@ class PdfGraphicState {
if
(
blendMode
!=
null
)
{
final
bm
=
blendMode
.
toString
();
print
(
bm
);
params
[
'/BM'
]
=
PdfName
(
'/'
+
bm
.
substring
(
13
,
14
).
toUpperCase
()
+
bm
.
substring
(
14
));
}
if
(
softMask
!=
null
)
{
params
[
'/SMask'
]
=
softMask
.
output
();
}
return
params
;
}
...
...
@@ -112,7 +119,9 @@ class PdfGraphicState {
if
(!(
other
is
PdfGraphicState
))
{
return
false
;
}
return
other
.
opacity
==
opacity
;
return
other
.
opacity
==
opacity
&&
other
.
blendMode
==
blendMode
&&
other
.
softMask
==
softMask
;
}
@override
...
...
pdf/lib/src/smask.dart
0 → 100644
View file @
c7403f6
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General License for more details.
*
* You should have received a copy of the GNU Lesser General
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import
'package:meta/meta.dart'
;
import
'package:pdf/pdf.dart'
;
import
'data_types.dart'
;
import
'document.dart'
;
import
'graphic_stream.dart'
;
import
'graphics.dart'
;
import
'rect.dart'
;
class
PdfSoftMask
{
PdfSoftMask
(
this
.
document
,
{
@required
PdfRect
boundingBox
,
bool
isolated
=
false
,
bool
knockout
=
false
,
bool
invert
=
false
})
:
assert
(
boundingBox
!=
null
),
assert
(
isolated
!=
null
),
assert
(
knockout
!=
null
),
assert
(
invert
!=
null
)
{
_mask
=
PdfGraphicXObject
(
document
);
_mask
.
params
[
'/BBox'
]
=
PdfArray
.
fromNum
([
boundingBox
.
x
,
boundingBox
.
y
,
boundingBox
.
width
,
boundingBox
.
height
,
]);
if
(
isolated
)
{
_mask
.
params
[
'/I'
]
=
const
PdfBool
(
true
);
}
if
(
knockout
)
{
_mask
.
params
[
'/K'
]
=
const
PdfBool
(
true
);
}
_graphics
=
PdfGraphics
(
_mask
,
_mask
.
buf
);
if
(
invert
)
{
_tr
=
PdfFunction
(
document
,
data:
[
255
,
0
],
);
}
}
final
PdfDocument
document
;
PdfGraphicXObject
_mask
;
PdfGraphics
_graphics
;
PdfGraphics
getGraphics
()
=>
_graphics
;
PdfBaseFunction
_tr
;
PdfDict
output
()
{
final
params
=
PdfDict
({
'/S'
:
const
PdfName
(
'/Luminosity'
),
'/G'
:
_mask
.
ref
(),
});
if
(
_tr
!=
null
)
{
params
[
'/TR'
]
=
_tr
.
ref
();
}
return
params
;
}
}
...
...
pdf/lib/src/xobject.dart
View file @
c7403f6
...
...
@@ -21,7 +21,9 @@ import 'object_stream.dart';
class
PdfXObject
extends
PdfObjectStream
{
PdfXObject
(
PdfDocument
pdfDocument
,
String
subtype
,
{
bool
isBinary
=
false
})
:
super
(
pdfDocument
,
type:
'/XObject'
,
isBinary:
isBinary
)
{
params
[
'/Subtype'
]
=
PdfName
(
subtype
);
if
(
subtype
!=
null
)
{
params
[
'/Subtype'
]
=
PdfName
(
subtype
);
}
}
String
get
name
=>
'X
$objser
'
;
...
...
Please
register
or
login
to post a comment