Showing
2 changed files
with
41 additions
and
10 deletions
@@ -20,6 +20,7 @@ import 'package:meta/meta.dart'; | @@ -20,6 +20,7 @@ import 'package:meta/meta.dart'; | ||
20 | 20 | ||
21 | import 'data_types.dart'; | 21 | import 'data_types.dart'; |
22 | import 'document.dart'; | 22 | import 'document.dart'; |
23 | +import 'function.dart'; | ||
23 | import 'object.dart'; | 24 | import 'object.dart'; |
24 | import 'smask.dart'; | 25 | import 'smask.dart'; |
25 | 26 | ||
@@ -83,22 +84,40 @@ enum PdfBlendMode { | @@ -83,22 +84,40 @@ enum PdfBlendMode { | ||
83 | @immutable | 84 | @immutable |
84 | class PdfGraphicState { | 85 | class PdfGraphicState { |
85 | /// Create a new graphic state | 86 | /// Create a new graphic state |
86 | - const PdfGraphicState({this.opacity, this.blendMode, this.softMask}); | ||
87 | - | ||
88 | - /// The opacity to apply to this graphic state | ||
89 | - final double? opacity; | 87 | + const PdfGraphicState({ |
88 | + double? opacity, | ||
89 | + double? strokeOpacity, | ||
90 | + double? fillOpacity, | ||
91 | + this.blendMode, | ||
92 | + this.softMask, | ||
93 | + this.transferFunction, | ||
94 | + }) : fillOpacity = fillOpacity ?? opacity, | ||
95 | + strokeOpacity = strokeOpacity ?? opacity; | ||
96 | + | ||
97 | + /// Fill opacity to apply to this graphic state | ||
98 | + final double? fillOpacity; | ||
99 | + | ||
100 | + /// Stroke opacity to apply to this graphic state | ||
101 | + final double? strokeOpacity; | ||
90 | 102 | ||
91 | /// The current blend mode to be used | 103 | /// The current blend mode to be used |
92 | final PdfBlendMode? blendMode; | 104 | final PdfBlendMode? blendMode; |
93 | 105 | ||
106 | + /// Opacity mask | ||
94 | final PdfSoftMask? softMask; | 107 | final PdfSoftMask? softMask; |
95 | 108 | ||
109 | + /// Color transfer function | ||
110 | + final PdfFunction? transferFunction; | ||
111 | + | ||
96 | PdfDict output() { | 112 | PdfDict output() { |
97 | final params = PdfDict(); | 113 | final params = PdfDict(); |
98 | 114 | ||
99 | - if (opacity != null) { | ||
100 | - params['/CA'] = PdfNum(opacity!); | ||
101 | - params['/ca'] = PdfNum(opacity!); | 115 | + if (strokeOpacity != null) { |
116 | + params['/CA'] = PdfNum(strokeOpacity!); | ||
117 | + } | ||
118 | + | ||
119 | + if (fillOpacity != null) { | ||
120 | + params['/ca'] = PdfNum(fillOpacity!); | ||
102 | } | 121 | } |
103 | 122 | ||
104 | if (blendMode != null) { | 123 | if (blendMode != null) { |
@@ -111,6 +130,10 @@ class PdfGraphicState { | @@ -111,6 +130,10 @@ class PdfGraphicState { | ||
111 | params['/SMask'] = softMask!.output(); | 130 | params['/SMask'] = softMask!.output(); |
112 | } | 131 | } |
113 | 132 | ||
133 | + if (transferFunction != null) { | ||
134 | + params['/TR'] = transferFunction!.ref(); | ||
135 | + } | ||
136 | + | ||
114 | return params; | 137 | return params; |
115 | } | 138 | } |
116 | 139 | ||
@@ -119,13 +142,20 @@ class PdfGraphicState { | @@ -119,13 +142,20 @@ class PdfGraphicState { | ||
119 | if (!(other is PdfGraphicState)) { | 142 | if (!(other is PdfGraphicState)) { |
120 | return false; | 143 | return false; |
121 | } | 144 | } |
122 | - return other.opacity == opacity && | 145 | + return other.fillOpacity == fillOpacity && |
146 | + other.strokeOpacity == strokeOpacity && | ||
123 | other.blendMode == blendMode && | 147 | other.blendMode == blendMode && |
124 | - other.softMask == softMask; | 148 | + other.softMask == softMask && |
149 | + other.transferFunction == transferFunction; | ||
125 | } | 150 | } |
126 | 151 | ||
127 | @override | 152 | @override |
128 | - int get hashCode => opacity.hashCode; | 153 | + int get hashCode => |
154 | + fillOpacity.hashCode * | ||
155 | + strokeOpacity.hashCode * | ||
156 | + blendMode.hashCode * | ||
157 | + softMask.hashCode * | ||
158 | + transferFunction.hashCode; | ||
129 | } | 159 | } |
130 | 160 | ||
131 | /// Stores all the graphic states used in the document | 161 | /// Stores all the graphic states used in the document |
-
Please register or login to post a comment