Unverified Commit c9381093 authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub
parent 1ecd5c8a
......@@ -134,10 +134,10 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_org_jetbrains_skia_paragraph_Para
auto conv = skija::UtfIndicesConverter(*text);
for (int i = 0; i < res.size(); ++i) {
LineMetrics lm = res[i];
size_t startIndex = conv.from8To16(lm.fStartIndex);
size_t endExcludingWhitespaces = conv.from8To16(lm.fEndExcludingWhitespaces);
size_t endIndex = conv.from8To16(lm.fEndIndex);
size_t endIncludingNewline = conv.from8To16(lm.fEndIncludingNewline);
size_t startIndex = lm.fStartIndex;
size_t endExcludingWhitespaces = lm.fEndExcludingWhitespaces;
size_t endIndex = lm.fEndIndex;
size_t endIncludingNewline = lm.fEndIncludingNewline;
jobject lmObj = env->NewObject(skija::paragraph::LineMetrics::cls, skija::paragraph::LineMetrics::ctor, startIndex, endIndex, endExcludingWhitespaces, endIncludingNewline, lm.fHardBreak, lm.fAscent, lm.fDescent, lm.fUnscaledAscent, lm.fHeight, lm.fWidth, lm.fLeft, lm.fBaseline, lm.fLineNumber);
env->SetObjectArrayElement(resArray, i, lmObj);
env->DeleteLocalRef(lmObj);
......
......@@ -2,14 +2,43 @@ package org.jetbrains.skiko
import org.jetbrains.skia.FontMgr
import org.jetbrains.skia.FontStyle
import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.paragraph.FontCollection
import org.jetbrains.skia.paragraph.LineMetrics
import org.jetbrains.skia.paragraph.ParagraphBuilder
import org.jetbrains.skia.paragraph.ParagraphStyle
import org.junit.Assert.assertEquals
import org.junit.Test
class ParagraphTest {
private val fontCollection = FontCollection().setDefaultFontManager(FontMgr.default)
@Test
fun findTypefaces() {
val fontCollection = FontCollection().setDefaultFontManager(FontMgr.default)
fontCollection.findTypefaces(emptyArray(), FontStyle.NORMAL)
}
private fun singleLineMetrics(text: String): LineMetrics {
val style = ParagraphStyle()
return ParagraphBuilder(style, fontCollection).use {
it.addText(text)
it.build()
}.layout(Float.POSITIVE_INFINITY).lineMetrics.first()
}
@Test
fun layoutParagraph() {
singleLineMetrics("aa").let { lineMetrics -> // latin
assertEquals(0, lineMetrics.startIndex)
assertEquals(2, lineMetrics.endIndex)
assertEquals(2, lineMetrics.endIncludingNewline)
assertEquals(2, lineMetrics.endExcludingWhitespaces)
}
singleLineMetrics("яя").let { lineMetrics -> // cyrillic
assertEquals(0, lineMetrics.startIndex)
assertEquals(2, lineMetrics.endIndex)
assertEquals(2, lineMetrics.endIncludingNewline)
assertEquals(2, lineMetrics.endExcludingWhitespaces)
}
}
}
\ No newline at end of file
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