1 /* 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "config.h" 27 28 #include "FontCustomPlatformData.h" 29 30 #include "SharedBuffer.h" 31 #include "FontDescription.h" 32 #include "FontPlatformData.h" 33 34 namespace WebCore { 35 36 FontCustomPlatformData::FontCustomPlatformData(const JLObject& data) 37 : m_data(data) 38 { 39 } 40 41 FontCustomPlatformData::~FontCustomPlatformData() 42 { 43 } 44 45 FontPlatformData FontCustomPlatformData::fontPlatformData( 46 const FontDescription& fontDescription, bool bold, bool italic) 47 { 48 JNIEnv* env = WebCore_GetJavaEnv(); 49 50 int size = fontDescription.computedPixelSize(); 51 static jmethodID mid = env->GetMethodID( 52 PG_GetFontCustomPlatformDataClass(env), 53 "createFont", 54 "(IZZ)Lcom/sun/webkit/graphics/WCFont;"); 55 ASSERT(mid); 56 57 JLObject font(env->CallObjectMethod( 58 m_data, 59 mid, 60 size, 61 bool_to_jbool(bold), 62 bool_to_jbool(italic))); 63 CheckAndClearException(env); 64 65 return FontPlatformData(RQRef::create(font), size); 66 } 67 68 std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer& buffer, unsigned /* index */) 69 { 70 JNIEnv* env = WebCore_GetJavaEnv(); 71 72 static JGClass sharedBufferClass(env->FindClass( 73 "com/sun/webkit/SharedBuffer")); 74 ASSERT(sharedBufferClass); 75 76 static jmethodID mid1 = env->GetStaticMethodID( 77 sharedBufferClass, 78 "fwkCreate", 79 "(J)Lcom/sun/webkit/SharedBuffer;"); 80 ASSERT(mid1); 81 82 JLObject sharedBuffer(env->CallStaticObjectMethod( 83 sharedBufferClass, 84 mid1, 85 ptr_to_jlong(&buffer))); 86 CheckAndClearException(env); 87 88 static jmethodID mid2 = env->GetMethodID( 89 PG_GetGraphicsManagerClass(env), 90 "fwkCreateFontCustomPlatformData", 91 "(Lcom/sun/webkit/SharedBuffer;)" 92 "Lcom/sun/webkit/graphics/WCFontCustomPlatformData;"); 93 ASSERT(mid2); 94 95 JLObject data(env->CallObjectMethod( 96 PL_GetGraphicsManager(env), 97 mid2, 98 (jobject) sharedBuffer)); 99 CheckAndClearException(env); 100 101 return data ? std::make_unique<FontCustomPlatformData>(data) : nullptr; 102 } 103 104 bool FontCustomPlatformData::supportsFormat(const String& format) 105 { 106 return equalLettersIgnoringASCIICase(format, "truetype") 107 || equalLettersIgnoringASCIICase(format, "opentype") 108 || equalLettersIgnoringASCIICase(format, "woff"); 109 } 110 111 }