下面列出了android.graphics.Path#FillType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static ShapeFill newInstance(JSONObject json, LottieComposition composition) {
AnimatableColorValue color = null;
boolean fillEnabled;
AnimatableIntegerValue opacity = null;
JSONObject jsonColor = json.optJSONObject("c");
if (jsonColor != null) {
color = AnimatableColorValue.Factory.newInstance(jsonColor, composition);
}
JSONObject jsonOpacity = json.optJSONObject("o");
if (jsonOpacity != null) {
opacity = AnimatableIntegerValue.Factory.newInstance(jsonOpacity, composition);
}
fillEnabled = json.optBoolean("fillEnabled");
int fillTypeInt = json.optInt("r", 1);
Path.FillType fillType = fillTypeInt == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;
return new ShapeFill(fillEnabled, fillType, color, opacity);
}
/**
* Fill the path.
*
* @param windingRule the winding rule to be used for filling
* @throws IOException If the content stream could not be written
* @throws IllegalArgumentException If the parameter is not a valid winding rule.
* @deprecated Use {@link #fill()} or {@link #fillEvenOdd} instead.
*/
@Deprecated
public void fill(Path.FillType windingRule) throws IOException
{
if (windingRule == Path.FillType.WINDING)
{
fill();
}
else if (windingRule == Path.FillType.EVEN_ODD)
{
fillEvenOdd();
}
else
{
throw new IllegalArgumentException("Error: unknown value for winding rule");
}
}
/**
* Clip path.
*
* @param windingRule the winding rule to be used for clipping
*
* @throws IOException If there is an error while clipping the path.
* @throws IllegalStateException If the method was called within a text block.
* @deprecated Use {@link #clip()} or {@link #clipEvenOdd} instead.
*/
@Deprecated
public void clipPath(Path.FillType windingRule) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: clipPath is not allowed within a text block.");
}
if (windingRule == Path.FillType.WINDING)
{
writeOperator("W");
}
else if (windingRule == Path.FillType.EVEN_ODD)
{
writeOperator("W");
}
else
{
throw new IllegalArgumentException("Error: unknown value for winding rule");
}
writeOperator("n");
}
public GradientFill(String name, GradientType gradientType, Path.FillType fillType,
AnimatableGradientColorValue gradientColor,
AnimatableIntegerValue opacity, AnimatablePointValue startPoint,
AnimatablePointValue endPoint, AnimatableFloatValue highlightLength,
AnimatableFloatValue highlightAngle, boolean hidden) {
this.gradientType = gradientType;
this.fillType = fillType;
this.gradientColor = gradientColor;
this.opacity = opacity;
this.startPoint = startPoint;
this.endPoint = endPoint;
this.name = name;
this.highlightLength = highlightLength;
this.highlightAngle = highlightAngle;
this.hidden = hidden;
}
private Path.FillType getFillTypeFromState()
{
if (state.style.fillRule != null && state.style.fillRule == Style.FillRule.EvenOdd)
return Path.FillType.EVEN_ODD;
else
return Path.FillType.WINDING;
}
private Path.FillType getClipRuleFromState()
{
if (state.style.clipRule != null && state.style.clipRule == Style.FillRule.EvenOdd)
return Path.FillType.EVEN_ODD;
else
return Path.FillType.WINDING;
}
private Path.FillType getClipRuleFromState()
{
if (state.style.clipRule == null)
return Path.FillType.WINDING;
switch (state.style.clipRule)
{
case EvenOdd:
return Path.FillType.EVEN_ODD;
case NonZero:
default:
return Path.FillType.WINDING;
}
}
static ShapeFill parse(
JsonReader reader, LottieComposition composition) throws IOException {
AnimatableColorValue color = null;
boolean fillEnabled = false;
AnimatableIntegerValue opacity = null;
String name = null;
int fillTypeInt = 1;
boolean hidden = false;
while (reader.hasNext()) {
switch (reader.selectName(NAMES)) {
case 0:
name = reader.nextString();
break;
case 1:
color = AnimatableValueParser.parseColor(reader, composition);
break;
case 2:
opacity = AnimatableValueParser.parseInteger(reader, composition);
break;
case 3:
fillEnabled = reader.nextBoolean();
break;
case 4:
fillTypeInt = reader.nextInt();
break;
case 5:
hidden = reader.nextBoolean();
break;
default:
reader.skipName();
reader.skipValue();
}
}
Path.FillType fillType = fillTypeInt == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;
return new ShapeFill(name, fillEnabled, fillType, color, opacity, hidden);
}
public ShapeFill(String name, boolean fillEnabled, Path.FillType fillType,
@Nullable AnimatableColorValue color, @Nullable AnimatableIntegerValue opacity, boolean hidden) {
this.name = name;
this.fillEnabled = fillEnabled;
this.fillType = fillType;
this.color = color;
this.opacity = opacity;
this.hidden = hidden;
}
/**
* Set the path's fill type. This defines how "inside" is computed.
*
* @param ft The new fill type for this path
*/
public void setFillType(Path.FillType ft) {
if (mPath.getFillType() == ft)
return;
mPath.setFillType(ft);
mDrawPath.setFillType(ft);
invalidateSelf();
}
private Path.FillType getFillTypeFromState()
{
if (state.style.fillRule == null)
return Path.FillType.WINDING;
switch (state.style.fillRule)
{
case EvenOdd:
return Path.FillType.EVEN_ODD;
case NonZero:
default:
return Path.FillType.WINDING;
}
}
@Override
public void fillPath(Path.FillType windingRule) throws IOException
{
// graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
paint.setColor(getNonStrokingColor());
setClip();
linePath.setFillType(windingRule);
// disable anti-aliasing for rectangular paths, this is a workaround to avoid small stripes
// which occur when solid fills are used to simulate piecewise gradients, see PDFBOX-2302
// note that we ignore paths with a width/height under 1 as these are fills used as strokes,
// see PDFBOX-1658 for an example
// RectF bounds = new RectF(();
// linePath.computeBounds(bounds, true);
// boolean noAntiAlias = isRectangular(linePath) && bounds.width() > 1 && bounds.height() > 1;
// if (noAntiAlias)
{
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
// RenderingHints.VALUE_ANTIALIAS_OFF);
}
// TODO: PdfBox-Android: Commit 7f5861f9559e30ad68f0bcbce5b9dd2e7c2621b5 ?
paint.setStyle(Paint.Style.FILL);
canvas.drawPath(linePath, paint);
linePath.reset();
// if (noAntiAlias)
{
// JDK 1.7 has a bug where rendering hints are reset by the above call to
// the setRenderingHint method, so we re-set all hints, see PDFBOX-2302
setRenderingHints();
}
}
/**
* Fills and then strokes the path.
*
* @param windingRule The winding rule this path will use.
* @throws IOException If there is an IO error while filling the path.
*/
@Override
public void fillAndStrokePath(Path.FillType windingRule) throws IOException
{
// TODO can we avoid cloning the path?
Path path = new Path(linePath);
fillPath(windingRule);
linePath = path;
strokePath();
}
public PathAssert hasFillType(Path.FillType type) {
isNotNull();
Path.FillType actualType = actual.getFillType();
assertThat(actualType) //
.overridingErrorMessage("Expected fill type <%s> but was <%s>.", type, actualType) //
.isEqualTo(type);
return this;
}
static GradientFill parse(
JsonReader reader, LottieComposition composition) throws IOException {
String name = null;
AnimatableGradientColorValue color = null;
AnimatableIntegerValue opacity = null;
GradientType gradientType = null;
AnimatablePointValue startPoint = null;
AnimatablePointValue endPoint = null;
Path.FillType fillType = Path.FillType.WINDING;
boolean hidden = false;
while (reader.hasNext()) {
switch (reader.selectName(NAMES)) {
case 0:
name = reader.nextString();
break;
case 1:
int points = -1;
reader.beginObject();
while (reader.hasNext()) {
switch (reader.selectName(GRADIENT_NAMES)) {
case 0:
points = reader.nextInt();
break;
case 1:
color = AnimatableValueParser.parseGradientColor(reader, composition, points);
break;
default:
reader.skipName();
reader.skipValue();
}
}
reader.endObject();
break;
case 2:
opacity = AnimatableValueParser.parseInteger(reader, composition);
break;
case 3:
gradientType = reader.nextInt() == 1 ? GradientType.LINEAR : GradientType.RADIAL;
break;
case 4:
startPoint = AnimatableValueParser.parsePoint(reader, composition);
break;
case 5:
endPoint = AnimatableValueParser.parsePoint(reader, composition);
break;
case 6:
fillType = reader.nextInt() == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;
break;
case 7:
hidden = reader.nextBoolean();
break;
default:
reader.skipName();
reader.skipValue();
}
}
return new GradientFill(
name, gradientType, fillType, color, opacity, startPoint, endPoint, null, null, hidden);
}
public Path.FillType getFillType() {
return fillType;
}
public Path.FillType getFillType() {
return fillType;
}
/**
* Fills and then strokes the path.
*
* @param windingRule The winding rule this path will use.
*/
public abstract void fillAndStrokePath(Path.FillType windingRule) throws IOException;
/**
* Return the path's fill type. This defines how "inside" is
* computed. The default value is WINDING.
*
* @return the path's fill type
*/
public Path.FillType getFillType() {
return mPath.getFillType();
}
/**
* Modify the current clipping path by intersecting it with the current path.
* The clipping path will not be updated until the succeeding painting operator is called.
*
* @param windingRule The winding rule which will be used for clipping.
*/
public abstract void clip(Path.FillType windingRule) throws IOException;