-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skia integration - preprocessing of shape geometry
- Loading branch information
Showing
294 changed files
with
51,516 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
include/** linguist-vendored | ||
lib/** linguist-vendored | ||
freetype/** linguist-vendored | ||
skia/** linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
#include "resolve-shape-geometry.h" | ||
|
||
#ifdef MSDFGEN_USE_SKIA | ||
|
||
#include <core/SkPath.h> | ||
#include <pathops/SkPathOps.h> | ||
#include "../core/Vector2.h" | ||
#include "../core/edge-segments.h" | ||
#include "../core/Contour.h" | ||
|
||
#ifdef _WIN32 | ||
#pragma comment(lib, "skia.lib") | ||
#endif | ||
|
||
namespace msdfgen { | ||
|
||
SkPoint pointToSkiaPoint(Point2 p) { | ||
return SkPoint::Make((SkScalar) p.x, (SkScalar) p.y); | ||
} | ||
|
||
Point2 pointFromSkiaPoint(const SkPoint p) { | ||
return Point2((double) p.x(), (double) p.y()); | ||
} | ||
|
||
void shapeToSkiaPath(SkPath &skPath, const Shape &shape) { | ||
for (std::vector<Contour>::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) { | ||
if (!contour->edges.empty()) { | ||
skPath.moveTo(pointToSkiaPoint(contour->edges.front()->point(0))); | ||
for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) { | ||
{ | ||
const LinearSegment *linearSegment = dynamic_cast<const LinearSegment *>(&**edge); | ||
if (linearSegment) | ||
skPath.lineTo(pointToSkiaPoint(linearSegment->p[1])); | ||
} { | ||
const QuadraticSegment *quadraticSegment = dynamic_cast<const QuadraticSegment *>(&**edge); | ||
if (quadraticSegment) | ||
skPath.quadTo(pointToSkiaPoint(quadraticSegment->p[1]), pointToSkiaPoint(quadraticSegment->p[2])); | ||
} { | ||
const CubicSegment *cubicSegment = dynamic_cast<const CubicSegment *>(&**edge); | ||
if (cubicSegment) | ||
skPath.cubicTo(pointToSkiaPoint(cubicSegment->p[1]), pointToSkiaPoint(cubicSegment->p[2]), pointToSkiaPoint(cubicSegment->p[3])); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void shapeFromSkiaPath(Shape &shape, const SkPath &skPath) { | ||
shape.contours.clear(); | ||
Contour *contour = &shape.addContour(); | ||
SkPath::Iter pathIterator(skPath, true); | ||
SkPoint edgePoints[4]; | ||
for (SkPath::Verb op; (op = pathIterator.next(edgePoints)) != SkPath::kDone_Verb;) { | ||
switch (op) { | ||
case SkPath::kMove_Verb: | ||
if (!contour->edges.empty()) | ||
contour = &shape.addContour(); | ||
break; | ||
case SkPath::kLine_Verb: | ||
contour->addEdge(new LinearSegment(pointFromSkiaPoint(edgePoints[0]), pointFromSkiaPoint(edgePoints[1]))); | ||
break; | ||
case SkPath::kQuad_Verb: | ||
contour->addEdge(new QuadraticSegment(pointFromSkiaPoint(edgePoints[0]), pointFromSkiaPoint(edgePoints[1]), pointFromSkiaPoint(edgePoints[2]))); | ||
break; | ||
case SkPath::kCubic_Verb: | ||
contour->addEdge(new CubicSegment(pointFromSkiaPoint(edgePoints[0]), pointFromSkiaPoint(edgePoints[1]), pointFromSkiaPoint(edgePoints[2]), pointFromSkiaPoint(edgePoints[3]))); | ||
break; | ||
default:; | ||
} | ||
} | ||
if (contour->edges.empty()) | ||
shape.contours.pop_back(); | ||
} | ||
|
||
bool resolveShapeGeometry(Shape &shape) { | ||
SkPath skPath; | ||
shapeToSkiaPath(skPath, shape); | ||
if (!Simplify(skPath, &skPath)) | ||
return false; | ||
// Skia's AsWinding doesn't seem to work for unknown reasons | ||
shapeFromSkiaPath(shape, skPath); | ||
shape.orientContours(); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#pragma once | ||
|
||
#include "../core/Shape.h" | ||
|
||
#ifdef MSDFGEN_USE_SKIA | ||
|
||
namespace msdfgen { | ||
|
||
/// Resolves any intersections within the shape by subdividing its contours using the Skia library and makes sure its contours have a consistent winding. | ||
bool resolveShapeGeometry(Shape &shape); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.