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: ...@@ -56,6 +56,7 @@ public:
void commitRunBuffer(const RunInfo& info) override { void commitRunBuffer(const RunInfo& info) override {
TextLine::Run& run = fLine->fRuns.back(); TextLine::Run& run = fLine->fRuns.back();
if (0 < info.glyphCount) {
int32_t glyph = 0; int32_t glyph = 0;
int32_t graphemesInGlyph = 1; int32_t graphemesInGlyph = 1;
SkScalar glyphLeft = run.fPos[glyph].fX; SkScalar glyphLeft = run.fPos[glyph].fX;
...@@ -84,6 +85,7 @@ public: ...@@ -84,6 +85,7 @@ public:
glyphLeft = glyphRight; glyphLeft = glyphRight;
} }
} }
}
fPosition += info.fAdvance.fX; fPosition += info.fAdvance.fX;
} }
......
...@@ -195,8 +195,7 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH ...@@ -195,8 +195,7 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH
Stats.onNativeCall() Stats.onNativeCall()
ManagedString(text).use { managedString -> ManagedString(text).use { managedString ->
interopScope { interopScope {
TextLine( val linePtr = _nShapeLine(
_nShapeLine(
_ptr, _ptr,
managedString._ptr, managedString._ptr,
getPtr(font), getPtr(font),
...@@ -204,7 +203,8 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH ...@@ -204,7 +203,8 @@ class Shaper internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerH
optsFeatures = arrayOfFontFeaturesToInterop(opts.features), optsFeatures = arrayOfFontFeaturesToInterop(opts.features),
optsBooleanProps = opts._booleanPropsToInt() optsBooleanProps = opts._booleanPropsToInt()
) )
) require(linePtr != NullPointer) { "Shape line: $text returned nullptr" }
TextLine(linePtr)
} }
} }
......
package org.jetbrains.skiko package org.jetbrains.skiko
import org.jetbrains.skia.Font import org.jetbrains.skia.*
import org.jetbrains.skia.ManagedString
import org.jetbrains.skia.TextLine
import org.jetbrains.skia.Typeface
import org.jetbrains.skia.impl.use import org.jetbrains.skia.impl.use
import org.jetbrains.skia.shaper.ShapingOptions
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertContentEquals import kotlin.test.assertContentEquals
import kotlin.test.assertEquals import kotlin.test.assertEquals
...@@ -227,4 +225,11 @@ class TextLineTest { ...@@ -227,4 +225,11 @@ class TextLineTest {
assertCloseEnough(expected = 48.0f, actual = textLine.getCoordAtOffset(2), epsilon = eps) assertCloseEnough(expected = 48.0f, actual = textLine.getCoordAtOffset(2), epsilon = eps)
assertCloseEnough(expected = 69.0f, actual = textLine.getCoordAtOffset(3), 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