David PHAM-VAN

Add soft mask

... ... @@ -15,6 +15,7 @@
- Automatically calculate Shape() bounding box
- Improve gradient functions
- Add blend mode
- Add soft mask
## 1.12.0
... ...
... ... @@ -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';
... ...
... ... @@ -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
... ...
/*
* 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;
}
}
... ...
... ... @@ -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';
... ...