Loading core/tests/coretests/src/android/text/TextShaperTest.java 0 → 100644 +46 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.text; import static com.google.common.truth.Truth.assertThat; import android.graphics.text.PositionedGlyphs; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class TextShaperTest { @Test public void testFontWithPath() { TextPaint p = new TextPaint(); p.setFontFeatureSettings("'wght' 900"); List<PositionedGlyphs> glyphs = StyledTextShaper.shapeText("a", 0, 1, TextDirectionHeuristics.LTR, p); assertThat(glyphs.size()).isEqualTo(1); // This test only passes if the font of the Latin font is variable font. assertThat(glyphs.get(0).getFont(0).getFile()).isNotNull(); } } graphics/java/android/graphics/fonts/Font.java +6 −1 Original line number Diff line number Diff line Loading @@ -687,7 +687,9 @@ public final class Font { charBuffer[3] = (char) ((packedAxis & 0x0000_00FF_0000_0000L) >> 32); axes[i] = new FontVariationAxis(new String(charBuffer), value); } Font.Builder builder = new Font.Builder(buffer) String path = nGetFontPath(ptr); File file = (path == null) ? null : new File(path); Font.Builder builder = new Font.Builder(buffer, file, "") .setWeight(weight) .setSlant(italic ? FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT) .setTtcIndex(ttcIndex) Loading @@ -711,6 +713,9 @@ public final class Font { @CriticalNative private static native long nGetAxisInfo(long ptr, int i); @FastNative private static native String nGetFontPath(long ptr); @FastNative private static native float nGetGlyphBounds(long font, int glyphId, long paint, RectF rect); Loading libs/hwui/jni/fonts/Font.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,17 @@ static jlong Font_getAxisInfo(CRITICAL_JNI_PARAMS_COMMA jlong fontHandle, jint i return (static_cast<uint64_t>(var.axisTag) << 32) | static_cast<uint64_t>(floatBinary); } // FastNative static jstring Font_getFontPath(JNIEnv* env, jobject, jlong fontHandle) { const minikin::Font* font = reinterpret_cast<minikin::Font*>(fontHandle); MinikinFontSkia* minikinSkia = static_cast<MinikinFontSkia*>(font->typeface().get()); const std::string& filePath = minikinSkia->getFilePath(); if (filePath.empty()) { return nullptr; } return env->NewStringUTF(filePath.c_str()); } // Critical Native static jlong Font_getNativeFontPtr(CRITICAL_JNI_PARAMS_COMMA jlong fontHandle) { FontWrapper* font = reinterpret_cast<FontWrapper*>(fontHandle); Loading Loading @@ -274,6 +285,7 @@ static const JNINativeMethod gFontMethods[] = { { "nGetFontMetrics", "(JJLandroid/graphics/Paint$FontMetrics;)F", (void*) Font_getFontMetrics }, { "nGetFontInfo", "(J)J", (void*) Font_getFontInfo }, { "nGetAxisInfo", "(JI)J", (void*) Font_getAxisInfo }, { "nGetFontPath", "(J)Ljava/lang/String;", (void*) Font_getFontPath }, { "nGetNativeFontPtr", "(J)J", (void*) Font_getNativeFontPtr }, }; Loading Loading
core/tests/coretests/src/android/text/TextShaperTest.java 0 → 100644 +46 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.text; import static com.google.common.truth.Truth.assertThat; import android.graphics.text.PositionedGlyphs; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class TextShaperTest { @Test public void testFontWithPath() { TextPaint p = new TextPaint(); p.setFontFeatureSettings("'wght' 900"); List<PositionedGlyphs> glyphs = StyledTextShaper.shapeText("a", 0, 1, TextDirectionHeuristics.LTR, p); assertThat(glyphs.size()).isEqualTo(1); // This test only passes if the font of the Latin font is variable font. assertThat(glyphs.get(0).getFont(0).getFile()).isNotNull(); } }
graphics/java/android/graphics/fonts/Font.java +6 −1 Original line number Diff line number Diff line Loading @@ -687,7 +687,9 @@ public final class Font { charBuffer[3] = (char) ((packedAxis & 0x0000_00FF_0000_0000L) >> 32); axes[i] = new FontVariationAxis(new String(charBuffer), value); } Font.Builder builder = new Font.Builder(buffer) String path = nGetFontPath(ptr); File file = (path == null) ? null : new File(path); Font.Builder builder = new Font.Builder(buffer, file, "") .setWeight(weight) .setSlant(italic ? FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT) .setTtcIndex(ttcIndex) Loading @@ -711,6 +713,9 @@ public final class Font { @CriticalNative private static native long nGetAxisInfo(long ptr, int i); @FastNative private static native String nGetFontPath(long ptr); @FastNative private static native float nGetGlyphBounds(long font, int glyphId, long paint, RectF rect); Loading
libs/hwui/jni/fonts/Font.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,17 @@ static jlong Font_getAxisInfo(CRITICAL_JNI_PARAMS_COMMA jlong fontHandle, jint i return (static_cast<uint64_t>(var.axisTag) << 32) | static_cast<uint64_t>(floatBinary); } // FastNative static jstring Font_getFontPath(JNIEnv* env, jobject, jlong fontHandle) { const minikin::Font* font = reinterpret_cast<minikin::Font*>(fontHandle); MinikinFontSkia* minikinSkia = static_cast<MinikinFontSkia*>(font->typeface().get()); const std::string& filePath = minikinSkia->getFilePath(); if (filePath.empty()) { return nullptr; } return env->NewStringUTF(filePath.c_str()); } // Critical Native static jlong Font_getNativeFontPtr(CRITICAL_JNI_PARAMS_COMMA jlong fontHandle) { FontWrapper* font = reinterpret_cast<FontWrapper*>(fontHandle); Loading Loading @@ -274,6 +285,7 @@ static const JNINativeMethod gFontMethods[] = { { "nGetFontMetrics", "(JJLandroid/graphics/Paint$FontMetrics;)F", (void*) Font_getFontMetrics }, { "nGetFontInfo", "(J)J", (void*) Font_getFontInfo }, { "nGetAxisInfo", "(JI)J", (void*) Font_getAxisInfo }, { "nGetFontPath", "(J)Ljava/lang/String;", (void*) Font_getFontPath }, { "nGetNativeFontPtr", "(J)J", (void*) Font_getNativeFontPtr }, }; Loading