Sekwencja wyboru czcionek w Aspose.Slides dla .NET

Przegląd

When a presentation is loaded, rendered, or converted to another format, Aspose.Slides considers its embedded fonts and the fonts available to the application. If a required font is unavailable, Aspose.Slides selects a replacement font that is as close as possible to the one PowerPoint would use.

Available fonts can include system fonts, fonts loaded by the application and fonts embedded in the presentation. For a matching embedded and registered font, the .NET 26.11 preference described below controls which takes priority. Font substitution rules defined through FontSubstRule are a separate mechanism.

You can also add fonts at application runtime, use embedded fonts from a presentation, or load external fonts for output documents such as PDF files.

Wybór czcionki

Text can reference a theme font, such as +mn-lt, rather than an explicit family name. See Rozwiązywanie odwołań do czcionek motywu to obtain the family specified by the applicable theme. Resolving that reference is separate from checking font availability and applying rendering-time substitution or glyph fallback; it does not identify the font file ultimately used to render the text.

When rendering slides or converting a presentation, check that the requested fonts are embedded or available from registered sources. Missing fonts can require replacement or substitution; see Zamiana czcionek and Podstawianie czcionek.

When investigating font selection:

  1. Resolve the requested family and style, including any theme reference.
  2. Check embedded fonts and registered sources, including system fonts and fonts loaded by the application. Use the preference below when matching embedded and registered versions compete.
  3. Review reguły podstawiania czcionek and glyph fallback if the requested font or characters are unavailable.

Aspose.Slides allows you to add fonts to application runtime and then use those fonts. See Czcionki niestandardowe.

When additional fonts are placed within a presentation, they are called Czcionki osadzone.

Aspose.Slides allows you to add fonts that are applied to only output documents. For example, if a presentation you are looking to convert to PDF contains fonts missing from your system and embedded fonts, you can add or load the needed fonts as external fonts.

Preferowanie czcionek zarejestrowanych nad czcionkami osadzonymi

Starting with .NET 26.11, IFontsManager.PreferRegisteredFontsOverEmbedded lets a matching registered font take priority over an embedded font during export. The default is false. Matching uses the font name and style; a different family name is not a replacement match. Registered fonts can come from the system or explicitly loaded font sources.

The following example uses the Aspose.Slides.NET6.CrossPlatform 26.11 package on .NET 8. Follow the przewodnik instalacji for your environment. Provide embedded-fonts.pptx with an embedded font and preferred.ttf with the same family name and style. The two font files should differ visibly if you want to compare the output.

using System.IO;
using Aspose.Slides;
using Aspose.Slides.Export;

var fontBytes = File.ReadAllBytes("preferred.ttf");
FontsLoader.LoadExternalFont(fontBytes);
using var presentation = new Presentation("embedded-fonts.pptx");

presentation.FontsManager.PreferRegisteredFontsOverEmbedded = false;
presentation.Save("embedded-preference.pdf", SaveFormat.Pdf);

presentation.FontsManager.PreferRegisteredFontsOverEmbedded = true;
presentation.Save("registered-preference.pdf", SaveFormat.Pdf);

presentation.FontsManager.PreferRegisteredFontsOverEmbedded = false;
presentation.Save("restored-preference.pdf", SaveFormat.Pdf);

This setting changes font precedence during the export; it does not rename the text’s font, remove embedded font data or re-embed the registered file. It is a runtime setting: set it again after reopening a presentation. If no matching registered font is available, enabling the preference does not supply one; verify the resulting font and layout in your target environment.

PNG and PDF output with explicitly loaded regular fonts were checked for the configuration above. Check your own font files, styles, SDK build and output formats before depending on identical results. Font metrics can change line breaks and positioning. Use zamiana czcionek or podstawianie when you need a different family, and operacje na czcionkach osadzonych when you need to change the fonts stored in the presentation.

FAQ

Jak mogę określić, które czcionki są faktycznie użyte w prezentacji przed konwersją?

Aspose.Slides umożliwia sprawdzenie używanych czcionek za pomocą menedżera czcionek, dzięki czemu możesz zdecydować, czy osadzić, zastąpić, czy dodać zewnętrzne źródła. To pomaga zapobiec niechcianym podstawieniom podczas renderowania i eksportu.

Czy mogę dodać dodatkowe katalogi czcionek bez instalowania ich w systemie operacyjnym?

Tak. Możesz zarejestrować zewnętrzne źródła czcionek, takie jak foldery lub strumienie w pamięci, do renderowania i eksportu. To usuwa zależność od czcionek systemowych i utrzymuje układ przewidywalnym.

Jak zapobiec cichej zmianie na nieodpowiednią czcionkę, gdy brakuje glifu?

Zdefiniuj explicite zamiana czcionek i font reguły zastępowania z wyprzedzeniem. Analizując używane czcionki i ustawiając kontrolowany priorytet dla zamienników, zapewniasz spójną typografię i unikasz nieoczekiwanych rezultatów.