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-02-03 07:35:19 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
800d2ba3dac458d5d241cc3835cd738c45208bb8
800d2ba3
1 parent
eae822d5
Add Opacity Widget
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
152 additions
and
4 deletions
pdf/CHANGELOG.md
pdf/lib/pdf.dart
pdf/lib/src/document.dart
pdf/lib/src/graphic_state.dart
pdf/lib/src/graphics.dart
pdf/lib/src/page.dart
pdf/lib/widgets/basic.dart
pdf/CHANGELOG.md
View file @
800d2ba
...
...
@@ -9,6 +9,7 @@
-
Fix HSV and HSL Color constructors
-
Add PageTheme.copyWith
-
Add more font drawing options
-
Add Opacity Widget
## 1.4.1
...
...
pdf/lib/pdf.dart
View file @
800d2ba
...
...
@@ -40,22 +40,23 @@ part 'src/colors.dart';
part
'src/compatibility.dart'
;
part
'src/document.dart'
;
part
'src/encryption.dart'
;
part
'src/font_descriptor.dart'
;
part
'src/exif.dart'
;
part
'src/font_metrics.dart'
;
part
'src/font.dart'
;
part
'src/font_descriptor.dart'
;
part
'src/font_metrics.dart'
;
part
'src/formxobject.dart'
;
part
'src/graphic_state.dart'
;
part
'src/graphics.dart'
;
part
'src/image.dart'
;
part
'src/info.dart'
;
part
'src/names.dart'
;
part
'src/object_stream.dart'
;
part
'src/object.dart'
;
part
'src/object_stream.dart'
;
part
'src/outline.dart'
;
part
'src/output.dart'
;
part
'src/page.dart'
;
part
'src/page_format.dart'
;
part
'src/page_list.dart'
;
part
'src/page.dart'
;
part
'src/point.dart'
;
part
'src/polygon.dart'
;
part
'src/rect.dart'
;
...
...
pdf/lib/src/document.dart
View file @
800d2ba
...
...
@@ -98,6 +98,9 @@ class PdfDocument {
/// Object used to sign the document
PdfSignature
sign
;
/// Graphics state, representing only opacity.
PdfGraphicStates
_graphicStates
;
/// The PDF specification version
final
String
version
=
'1.7'
;
...
...
@@ -149,6 +152,14 @@ class PdfDocument {
return
_outline
;
}
/// Graphic states for opacity and transfer modes
PdfGraphicStates
get
graphicStates
{
_graphicStates
??=
PdfGraphicStates
(
this
);
return
_graphicStates
;
}
bool
get
hasGraphicStates
=>
_graphicStates
!=
null
;
/// This writes the document to an OutputStream.
///
/// Note: You can call this as many times as you wish, as long as
...
...
pdf/lib/src/graphic_state.dart
0 → 100644
View file @
800d2ba
/*
* 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
*/
// ignore_for_file: omit_local_variable_types
part of
pdf
;
@immutable
class
PdfGraphicState
{
const
PdfGraphicState
({
this
.
opacity
});
final
double
opacity
;
@protected
PdfStream
_output
()
{
final
Map
<
String
,
PdfStream
>
params
=
<
String
,
PdfStream
>{};
if
(
opacity
!=
null
)
{
params
[
'/CA'
]
=
PdfStream
.
num
(
opacity
);
params
[
'/ca'
]
=
PdfStream
.
num
(
opacity
);
}
return
PdfStream
.
dictionary
(
params
);
}
@override
bool
operator
==(
dynamic
other
)
{
if
(!
other
is
PdfGraphicState
)
{
return
false
;
}
return
other
.
opacity
==
opacity
;
}
@override
int
get
hashCode
=>
opacity
.
hashCode
;
}
class
PdfGraphicStates
extends
PdfObject
{
PdfGraphicStates
(
PdfDocument
pdfDocument
)
:
super
(
pdfDocument
);
final
List
<
PdfGraphicState
>
_states
=
<
PdfGraphicState
>[];
static
const
String
_prefix
=
'/a'
;
String
stateName
(
PdfGraphicState
state
)
{
int
index
=
_states
.
indexOf
(
state
);
if
(
index
<
0
)
{
index
=
_states
.
length
;
_states
.
add
(
state
);
}
return
'
$_prefix$index
'
;
}
@override
void
_prepare
()
{
super
.
_prepare
();
for
(
int
index
=
0
;
index
<
_states
.
length
;
index
++)
{
params
[
'
$_prefix$index
'
]
=
_states
[
index
].
_output
();
}
}
}
...
...
pdf/lib/src/graphics.dart
View file @
800d2ba
...
...
@@ -320,6 +320,12 @@ class PdfGraphics {
}
}
/// Set the graphic state for drawing
void
setGraphicState
(
PdfGraphicState
state
)
{
final
String
name
=
page
.
pdfDocument
.
graphicStates
.
stateName
(
state
);
buf
.
putString
(
'
$name
gs
\n
'
);
}
/// Set the transformation Matrix
void
setTransform
(
Matrix4
t
)
{
final
Float64List
s
=
t
.
storage
;
...
...
pdf/lib/src/page.dart
View file @
800d2ba
...
...
@@ -41,6 +41,18 @@ class PdfPage extends PdfObject {
/// -1 indicates no thumbnail.
PdfObject
thumbnail
;
/// Isolated transparency: If this flag is true, objects within the group
/// shall be composited against a fully transparent initial backdrop;
/// if false, they shall be composited against the group’s backdrop
bool
isolatedTransparency
=
false
;
/// Whether the transparency group is a knockout group.
/// If this flag is false, later objects within the group shall be composited
/// with earlier ones with which they overlap; if true, they shall be
/// composited with the group’s initial backdrop and shall overwrite any
/// earlier overlapping objects.
bool
knockoutTransparency
=
false
;
/// This holds any Annotations contained within this page.
List
<
PdfAnnot
>
annotations
=
<
PdfAnnot
>[];
...
...
@@ -115,6 +127,20 @@ class PdfPage extends PdfObject {
resources
[
'/XObject'
]
=
PdfStream
()..
putObjectDictionary
(
xObjects
);
}
if
(
pdfDocument
.
hasGraphicStates
)
{
// Declare Transparency Group settings
params
[
'/Group'
]
=
PdfStream
()
..
putDictionary
(<
String
,
PdfStream
>{
'/Type'
:
PdfStream
.
string
(
'/Group'
),
'/S'
:
PdfStream
.
string
(
'/Transparency'
),
'/CS'
:
PdfStream
.
string
(
'/DeviceRGB'
),
'/I'
:
PdfStream
()..
putBool
(
isolatedTransparency
),
'/K'
:
PdfStream
()..
putBool
(
knockoutTransparency
),
});
resources
[
'/ExtGState'
]
=
pdfDocument
.
graphicStates
.
ref
();
}
params
[
'/Resources'
]
=
PdfStream
.
dictionary
(
resources
);
// The thumbnail
...
...
pdf/lib/widgets/basic.dart
View file @
800d2ba
...
...
@@ -740,3 +740,29 @@ class FullPage extends SingleChildWidget {
context
.
canvas
.
restoreContext
();
}
}
class
Opacity
extends
SingleChildWidget
{
Opacity
({
@required
this
.
opacity
,
Widget
child
,
})
:
assert
(
opacity
!=
null
),
super
(
child:
child
);
final
double
opacity
;
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
if
(
child
!=
null
)
{
final
Matrix4
mat
=
Matrix4
.
identity
();
mat
.
translate
(
box
.
x
,
box
.
y
);
context
.
canvas
..
saveContext
()
..
setTransform
(
mat
)
..
setGraphicState
(
PdfGraphicState
(
opacity:
opacity
));
child
.
paint
(
context
);
context
.
canvas
.
restoreContext
();
}
}
}
...
...
Please
register
or
login
to post a comment