سيرشدك هذا البرنامج التعليمي السريع إلى ** كيفية جلب مقاييس الخط باستخدام Java **. سيتوفر وصف تفصيلي مع نموذج التعليمات البرمجية للحصول على مقاييس الخط باستخدام Java بحيث يتم تكوين البيئة أولاً ثم ستحصل على إجراء خطوة بخطوة وكود Java يعمل لتحميل PFB الخط وجلب مقاييس الخط. يمكن استخدام هذه العملية لاسترداد مقاييس الخط في أي من أنظمة التشغيل الشائعة مثل Windows أو macOS أو Linux.
خطوات جلب مقاييس الخط باستخدام Java
- تكوين مكتبة Aspose.Font من مستودع Maven لجلب مقاييس الخط في التطبيق
- قم بتحميل نموذج ملف خط PFB في كائن فئة FileSystemStreamSource لاسترداد المقاييس
- قم بتعريف كائن فئة FontFileDefinition عن طريق توفير كائن FileSystemStreamSource
- تهيئة كائن فئة FontDefinition وتعيين FontType وكائن FontFileDefinition
- استخدم وظيفة Font.open لتحميل تعريف الخط وإرساله كـ Type1Font
- قم بإحضار وعرض كافة معلومات مقاييس الخط المطلوبة باستخدام كائن Type1Font
تصف هذه الخطوات طريقة خطوة بخطوة لتحميل ملف خط PFB ثم استخدام سلسلة من كائنات الفئات المختلفة المطلوبة لجلب تعريف الخط ثم * استخراج مقاييس الخط باستخدام Java *. تتوفر جميع معلومات مقاييس الخط الضرورية في كائن فئة Type1Font.
رمز لاسترداد مقاييس الخط باستخدام Java
import com.aspose.cells.License; | |
import com.aspose.font.FileSystemStreamSource; | |
import com.aspose.font.Font; | |
import com.aspose.font.FontDefinition; | |
import com.aspose.font.FontFileDefinition; | |
import com.aspose.font.FontType; | |
import com.aspose.font.Type1Font; | |
public class HowToFetchFontMetricsInJava { | |
public static void main(String[] args) throws Exception { //main function for HowToFetchFontMetricsInJava class to get Type1Font Metrics | |
// Instantiate the license for Aspose.Font to avoid trial version limitations before fetching the Font Metrics | |
License licenseFont = new License(); | |
licenseFont.setLicense("Aspose.Font.lic"); | |
// Load the sample Type1Font PFB file into FileSystemStreamSource | |
FileSystemStreamSource fileSystemStreamSource = new FileSystemStreamSource("Type1FontSampleInput.pfb"); | |
// Instantiate FontFileDefinition class object using the FileSystemStreamSource object as argument | |
FontFileDefinition fontFileDefinition = new FontFileDefinition(fileSystemStreamSource); | |
// Instantiate font definition class object by providing the FontType and FontFileDefinition class object | |
FontDefinition fontDefinition = new FontDefinition(FontType.Type1, fontFileDefinition); | |
// Using the font definition, initialize the Type1Font class object | |
Type1Font type1Font = (Type1Font) Font.open(fontDefinition); | |
// Using this TypeFont class object, retrieve the font metrics information and display it on the console | |
System.out.print( | |
"FontName = " + type1Font.getFontName() + | |
", FontGlyphcount = " + type1Font.getNumGlyphs()+ | |
", FontMetricsAscender = " + type1Font.getMetrics().getAscender() + | |
", FontMetricsDescender = " + type1Font.getMetrics().getDescender() + | |
", FontMetricsTypoAscender = " + type1Font.getMetrics().getTypoAscender() + | |
", FontMetricsTypoDescender = " + type1Font.getMetrics().getTypoDescender() + | |
", FontMetricsUnitsPerEM = " + type1Font.getMetrics().getUnitsPerEM() | |
); | |
} | |
} |
في نموذج التعليمات البرمجية هذا ، نقوم أولاً بتحميل ملف PFB ثم نستخدم فئة Type1Font لفتح تعريف الخط الذي تم تحميله. تحتوي الفئة Type1Font على خصائص مثل FontName و NumGlyphs و Ascender و Descender و TypoAscender و TypoDescender و UnitsPerEM. يمكنك استرداد هذه الخصائص لعرضها على وحدة التحكم أو معالجتها وفقًا لمتطلبات التطبيق الخاص بك.
في هذا البرنامج التعليمي ، انتقلنا من خلال الخطوات * لاسترداد مقاييس الخط باستخدام Java *. إذا كنت تريد معرفة ميزات أخرى مثل تحويل ملف Word إلى JPG ، فراجع المقالة على كيفية تحويل Word إلى JPG في Java.