Unverified Commit 5825d5c4 authored by Pavel's avatar Pavel Committed by GitHub

don't crash an app if we got empty run during text shaping (#821)

* don't crash an app if we got empty run during text shaping

* on windows and linux it may produce some glyph
parent 748b0047
......@@ -56,6 +56,7 @@ public:
void commitRunBuffer(const RunInfo& info) override {
TextLine::Run& run = fLine->fRuns.back();
if (0 < info.glyphCount) {
int32_t glyph = 0;
int32_t graphemesInGlyph = 1;
SkScalar glyphLeft = run.fPos[glyph].fX;
......@@ -84,6 +85,7 @@ public:
glyphLeft = glyphRight;
}
}
}
fPosition += info.fAdvance.fX;
}
......
......@@ -195,8 +195,7 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH
Stats.onNativeCall()
ManagedString(text).use { managedString ->
interopScope {
TextLine(
_nShapeLine(
val linePtr = _nShapeLine(
_ptr,
managedString._ptr,
getPtr(font),
......@@ -204,7 +203,8 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH
optsFeatures = arrayOfFontFeaturesToInterop(opts.features),
optsBooleanProps = opts._booleanPropsToInt()
)
)
require(linePtr != NullPointer) { "Shape line: $text returned nullptr" }
TextLine(linePtr)
}
}
......
package org.jetbrains.skiko
import org.jetbrains.skia.Font
import org.jetbrains.skia.ManagedString
import org.jetbrains.skia.TextLine
import org.jetbrains.skia.Typeface
import org.jetbrains.skia.*
import org.jetbrains.skia.impl.use
import org.jetbrains.skia.shaper.ShapingOptions
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
......@@ -227,4 +225,11 @@ class TextLineTest {
assertCloseEnough(expected = 48.0f, actual = textLine.getCoordAtOffset(2), epsilon = eps)
assertCloseEnough(expected = 69.0f, actual = textLine.getCoordAtOffset(3), epsilon = eps)
}
@Test
fun dontCrashOnStringsWithoutGlyphs() = runTest {
val failedOn = "\uFE0F" // Variation Selector-16
val textLine = TextLine.make(failedOn, jbMono36(), ShapingOptions.DEFAULT)
assertCloseEnough(expected = 0f, actual = textLine.width)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment