mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Anti-anti-alias
This commit is contained in:
parent
a74e5882cd
commit
a4045df526
1 changed files with 30 additions and 8 deletions
|
@ -11,7 +11,7 @@ import {trim} from '../helper/bitmap';
|
||||||
import {performSnapshot} from '../helper/undo';
|
import {performSnapshot} from '../helper/undo';
|
||||||
import {undoSnapshot, clearUndoState} from '../reducers/undo';
|
import {undoSnapshot, clearUndoState} from '../reducers/undo';
|
||||||
import {isGroup, ungroupItems} from '../helper/group';
|
import {isGroup, ungroupItems} from '../helper/group';
|
||||||
import {clearRaster, getRaster, setupLayers} from '../helper/layer';
|
import {clearRaster, getRaster, setupLayers, hideGuideLayers, showGuideLayers} from '../helper/layer';
|
||||||
import {deleteSelection, getSelectedLeafItems} from '../helper/selection';
|
import {deleteSelection, getSelectedLeafItems} from '../helper/selection';
|
||||||
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
||||||
import {pan, resetZoom, zoomOnFixedPoint} from '../helper/view';
|
import {pan, resetZoom, zoomOnFixedPoint} from '../helper/view';
|
||||||
|
@ -82,14 +82,36 @@ class PaperCanvas extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
convertToBitmap () {
|
convertToBitmap () {
|
||||||
this.props.clearSelectedItems();
|
// @todo if the active layer contains only rasters, drawing them directly to the raster layer
|
||||||
const raster = paper.project.activeLayer.rasterize(72, false /* insert */);
|
// would be more efficient.
|
||||||
raster.onLoad = function () {
|
// Export svg
|
||||||
const subCanvas = raster.canvas;
|
const guideLayers = hideGuideLayers(true /* includeRaster */);
|
||||||
getRaster().drawImage(subCanvas, raster.bounds.topLeft);
|
const bounds = paper.project.activeLayer.bounds;
|
||||||
paper.project.activeLayer.removeChildren();
|
const svg = paper.project.exportSVG({
|
||||||
this.props.onUpdateSvg();
|
bounds: 'content',
|
||||||
|
matrix: new paper.Matrix().translate(-bounds.x, -bounds.y)
|
||||||
|
});
|
||||||
|
showGuideLayers(guideLayers);
|
||||||
|
|
||||||
|
// Get rid of anti-aliasing
|
||||||
|
// @todo get crisp text?
|
||||||
|
svg.setAttribute('shape-rendering', 'optimizeSpeed');
|
||||||
|
const svgString = (new XMLSerializer()).serializeToString(svg);
|
||||||
|
|
||||||
|
// Put anti-aliased SVG into image, and dump image back into canvas
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = function () {
|
||||||
|
const raster = new paper.Raster(img);
|
||||||
|
raster.onLoad = function () {
|
||||||
|
const subCanvas = raster.canvas;
|
||||||
|
getRaster().drawImage(
|
||||||
|
subCanvas,
|
||||||
|
new paper.Point(Math.floor(bounds.topLeft.x), Math.floor(bounds.topLeft.y)));
|
||||||
|
paper.project.activeLayer.removeChildren();
|
||||||
|
this.props.onUpdateSvg();
|
||||||
|
}.bind(this);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
img.src = `data:image/svg+xml;charset=utf-8,${svgString}`;
|
||||||
}
|
}
|
||||||
convertToVector () {
|
convertToVector () {
|
||||||
this.props.clearSelectedItems();
|
this.props.clearSelectedItems();
|
||||||
|
|
Loading…
Reference in a new issue