Skip to content

Commit

Permalink
Fixed infinite loop in Trivial iterators (closes #63)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Nov 27, 2020
1 parent c02cf05 commit 57ec197
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ public FontScene() {

public float _drawLine(Canvas canvas, String text, Font font) {
var blob = Shaper.make().shape(text, font);
var bounds = blob.getBounds();
canvas.drawTextBlob(blob, 0, 0, font, _paint);
canvas.translate(0, bounds.getHeight());
return bounds.getHeight();
if (blob != null) {
var bounds = blob.getBounds();
canvas.drawTextBlob(blob, 0, 0, font, _paint);
canvas.translate(0, bounds.getHeight());
return bounds.getHeight();
}
return 0;
}

@Override
Expand All @@ -77,7 +80,7 @@ public void draw(Canvas canvas, int windowWidth, int windowHeight, float dpi, in
}

public void drawInter(Canvas canvas) {

_drawLine(canvas, "", _defaultFont);
_drawLine(canvas, "Default", _defaultFont);
_drawLine(canvas, "Inter size=18", _inter18);
_drawLine(canvas, "Inter size=13 scaleX=1", _inter13_1_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void drawMetrics(Canvas canvas, float dx, float dy) {
pb.addText(" is true\n");

pb.pushStyle(largeTs);
pb.addText("The previous ");
pb.addText("The previous ");
pb.popStyle();
pb.addText("sentence");
pb.pushStyle(largeTs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int
private void drawBlob(Canvas canvas, DebugTextBlobHandler handler, String comment) {
canvas.drawString(comment, 0, -inter11Metrics.getAscent(), inter11, textFill);
canvas.translate(0, inter11Metrics.getHeight());

try (var blob = handler._builder.build()) {
canvas.drawTextBlob(blob, 0, 0, lato36, textFill);

for (var triple: handler._infos) {
var runBounds = triple.getThird();
canvas.drawRect(runBounds, boundsStroke);
var blob = handler._builder.build();
if (blob != null) {
try (blob) {
canvas.drawTextBlob(blob, 0, 0, lato36, textFill);

for (var triple: handler._infos) {
var runBounds = triple.getThird();
canvas.drawRect(runBounds, boundsStroke);
}

canvas.translate(0, blob.getBounds().getBottom() + 20);
}

canvas.translate(0, blob.getBounds().getBottom() + 20);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ public void commitLine() {
throw new UnsupportedOperationException("commitLine");
}

@Nullable
public TextBlob makeBlob() {
Stats.onNativeCall();
long ptr = _nMakeBlob(_ptr);
if (0 == ptr)
throw new RuntimeException("Failed to shape: " + _text);
return new TextBlob(ptr);
return 0 == ptr ? null : new TextBlob(ptr);
}

@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
public class TrivialBidiRunIterator implements Iterator<BidiRun> {
@ApiStatus.Internal public final int _length;
@ApiStatus.Internal public final int _level;
@ApiStatus.Internal public boolean _atEnd = false;
@ApiStatus.Internal public boolean _atEnd;

public TrivialBidiRunIterator(String text, int level) {
_length = text.length();
_level = level;
_level = level;
_atEnd = _length == 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
public class TrivialFontRunIterator implements Iterator<FontRun> {
@ApiStatus.Internal public final int _length;
@ApiStatus.Internal public final Font _font;
@ApiStatus.Internal public boolean _atEnd = false;
@ApiStatus.Internal public boolean _atEnd;

public TrivialFontRunIterator(String text, Font font) {
_length = text.length();
_font = font;
_font = font;
_atEnd = _length == 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
public class TrivialLanguageRunIterator implements Iterator<LanguageRun> {
@ApiStatus.Internal public final int _length;
@ApiStatus.Internal public final String _language;
@ApiStatus.Internal public boolean _atEnd = false;
@ApiStatus.Internal public boolean _atEnd;

public TrivialLanguageRunIterator(String text, String language) {
_length = text.length();
_length = text.length();
_language = language;
_atEnd = _length == 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
public class TrivialScriptRunIterator implements Iterator<ScriptRun> {
@ApiStatus.Internal public final int _length;
@ApiStatus.Internal public final String _script;
@ApiStatus.Internal public boolean _atEnd = false;
@ApiStatus.Internal public boolean _atEnd;

public TrivialScriptRunIterator(String text, String script) {
_length = text.length();
_script = script;
_atEnd = _length == 0;
}

@Override
Expand Down

0 comments on commit 57ec197

Please sign in to comment.