restore method
Restores the state of this Graphics to the state represented by a GraphicsState.
//Creates a new PDF document.
PdfDocument doc = PdfDocument();
//Create PDF graphics for the page
PdfGraphics graphics = doc.pages.add().graphics;
//Save the graphics.
PdfGraphicsState state = graphics.save();
//Set graphics translate transform.
graphics
..translateTransform(100, 100)
..drawString('Hello world!', PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.red)
//Restore the graphics.
..restore(state);
//Saves the document.
List<int> bytes = doc.save();
//Dispose the document.
doc.dispose();
Implementation
void restore([PdfGraphicsState? state]) {
if (state == null) {
if (_graphicsState.isNotEmpty) {
_doRestoreState();
}
} else {
if (state._graphics != this) {
throw ArgumentError.value(
this, 'The graphics state belongs to another graphics object');
}
if (_graphicsState.contains(state)) {
while (true) {
if (_graphicsState.isEmpty) {
break;
}
final PdfGraphicsState popState = _doRestoreState();
if (popState == state) {
break;
}
}
}
}
}