Glifi e metriche dei caratteri TrueType | C ++
Ottieni metriche di carattere
I file di carattere possono essere contenuti informazioni su metriche come Ascender
, Descender
, TypoAscender
, TypoDescender
e UnitsPerEm
. Queste informazioni possono essere recuperate da file di carattere utilizzando Aspose.Font per API C ++ può leggere le informazioni sulle metriche dei caratteri dal file font TrueType utilizzando il seguente codice di esempio.
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::String fileName = dataDir + u"Montserrat-Regular.ttf";
3//Font file name with full path
4
5System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
6System::SharedPtr<TtfFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
7
8bool latinText = true;
9
10
11for (uint32_t code = 65; code < static_cast<uint32_t>(123); code++)
12{
13 System::SharedPtr<GlyphId> gid = ttfFont->get_Encoding()->DecodeToGid(code);
14 if (gid == nullptr || gid == System::StaticCast<System::Object>(GlyphUInt32Id::get_NotDefId()))
15 {
16 latinText = false;
17 }
18}
19
20if (latinText)
21{
22 System::Console::WriteLine(System::String::Format(u"Font {0} supports latin symbols.", ttfFont->get_FontName()));
23}
24else
25{
26 System::Console::WriteLine(System::String::Format(u"Latin symbols are not supported by font {0}.", ttfFont->get_FontName()));
27}
Rileva i simboli latini
Aspose.Font per C ++ può rilevare i simboli latini dai file di carattere TrueType. Questo può essere ottenuto utilizzando il seguente codice di esempio.
- Carica il file font utilizzando FontFileDefinition
- Decodifica il glyphid usando il metodo DecodeToGid()
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::String dataDir = RunExamples::GetDataDir_Data();
3//Font to check
4System::String fileName = dataDir + u"Montserrat-Regular.ttf";
5//Font file name with full path
6
7System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
8System::SharedPtr<TtfFont> font = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
9System::SharedPtr<LicenseFlags> licenseFlags;
10if (font->get_TtfTables()->get_Os2Table() != nullptr)
11{
12 licenseFlags = font->get_TtfTables()->get_Os2Table()->GetLicenseFlags();
13}
14
15if (licenseFlags == nullptr || licenseFlags->get_FSTypeAbsent())
16{
17 System::Console::WriteLine(System::String::Format(u"Font {0} has no embedded license restrictions", font->get_FontName()));
18}
19else
20{
21 if (licenseFlags->get_IsEditableEmbedding())
22 {
23 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be temporarily loaded on other systems.", font->get_FontName()) + u" In addition, editing is permitted, including ability to format new text" + u" using the embedded font, and changes may be saved.");
24 }
25 else if (licenseFlags->get_IsInstallableEmbedding())
26 {
27 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be permanently installed", font->get_FontName()) + u" for use on a remote systems, or for use by other users.");
28 }
29 else if (licenseFlags->get_IsPreviewAndPrintEmbedding())
30 {
31 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be temporarily loaded", font->get_FontName()) + u" on other systems for purposes of viewing or printing the document.");
32 }
33 else if (licenseFlags->get_IsRestrictedLicenseEmbedding())
34 {
35 System::Console::WriteLine(System::String::Format(u"Font {0} must not be modified, embedded or exchanged in any manner", font->get_FontName()) + u" without first obtaining explicit permission of the legal owner.");
36 }
37}
Estrai restrizioni di licenza
I file di carattere possono contenere informazioni di licenza in una delle seguenti modalità.
- Il carattere di incorporamento “modificabile” può essere incorporato e può essere temporaneamente caricato su altri sistemi. Inoltre, è consentito l’editing, inclusa la capacità di formattare un nuovo testo usando il carattere incorporato e le modifiche possono essere salvate.
Installable Embedding
- Il carattere può essere incorporato e può essere installato permanentemente per l’uso su un sistema remoto o per l’uso da parte di altri utenti.Anteprima e stampa Incorniciatura
- Il carattere può essere incorporato e può essere temporaneamente caricato su altri sistemi a fini di visualizzazione o stampa del documento.- Il carattere “incorporato” - Il carattere non deve essere modificato, incorporato o scambiato in alcun modo senza prima ottenere l’autorizzazione esplicita del proprietario legale.
Utilizzando Aspose.Font per C ++, le restrizioni di licenza possono essere estratte da file di carattere. Il seguente campione di codice C ++ mostra come utilizzare un oggetto di Aspose.Font.ttf.licenseflags per ottenere informazioni sulle restrizioni della licenza di carattere (flag fstype dalla tabella OS/2) in forma conveniente.
1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
2System::String dataDir = RunExamples::GetDataDir_Data();
3//Font to check
4System::String fileName = dataDir + u"Montserrat-Regular.ttf";
5//Font file name with full path
6
7System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
8System::SharedPtr<TtfFont> font = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
9System::SharedPtr<LicenseFlags> licenseFlags;
10if (font->get_TtfTables()->get_Os2Table() != nullptr)
11{
12 licenseFlags = font->get_TtfTables()->get_Os2Table()->GetLicenseFlags();
13}
14
15if (licenseFlags == nullptr || licenseFlags->get_FSTypeAbsent())
16{
17 System::Console::WriteLine(System::String::Format(u"Font {0} has no embedded license restrictions", font->get_FontName()));
18}
19else
20{
21 if (licenseFlags->get_IsEditableEmbedding())
22 {
23 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be temporarily loaded on other systems.", font->get_FontName()) + u" In addition, editing is permitted, including ability to format new text" + u" using the embedded font, and changes may be saved.");
24 }
25 else if (licenseFlags->get_IsInstallableEmbedding())
26 {
27 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be permanently installed", font->get_FontName()) + u" for use on a remote systems, or for use by other users.");
28 }
29 else if (licenseFlags->get_IsPreviewAndPrintEmbedding())
30 {
31 System::Console::WriteLine(System::String::Format(u"Font {0} may be embedded, and may be temporarily loaded", font->get_FontName()) + u" on other systems for purposes of viewing or printing the document.");
32 }
33 else if (licenseFlags->get_IsRestrictedLicenseEmbedding())
34 {
35 System::Console::WriteLine(System::String::Format(u"Font {0} must not be modified, embedded or exchanged in any manner", font->get_FontName()) + u" without first obtaining explicit permission of the legal owner.");
36 }
37}