Skip to content

Commit 8b0edbf

Browse files
Copilotyufeih
andcommitted
Add cross-platform emoji font paths and improve documentation
Co-authored-by: yufeih <511355+yufeih@users.noreply.github.com>
1 parent 60c92e8 commit 8b0edbf

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Docfx.App/PdfBuilder.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ static class PdfBuilder
3535
{
3636
private static readonly SearchValues<char> InvalidPathChars = SearchValues.Create(Path.GetInvalidPathChars());
3737

38-
// Environment variable to specify a font path that supports emoji characters
38+
/// <summary>
39+
/// Environment variable to specify a custom path to a TrueType font that supports emoji characters.
40+
/// If not set, DocFX will automatically look for Noto Color Emoji font in common system locations.
41+
/// Example: DOCFX_PDF_EMOJI_FONT=/path/to/NotoColorEmoji.ttf
42+
/// </summary>
3943
private const string EmojiFontPathEnvVar = "DOCFX_PDF_EMOJI_FONT";
4044

41-
// Common paths for Noto Color Emoji font on Linux systems
45+
// Common paths for Noto Color Emoji font on various systems
4246
private static readonly string[] KnownEmojiPaths = new[]
4347
{
44-
"/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf", // Ubuntu with fonts-noto-color-emoji
45-
"/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf" // Some other distributions
48+
"/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf", // Ubuntu with fonts-noto-color-emoji
49+
"/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf", // Some other Linux distributions
50+
"/System/Library/Fonts/Apple Color Emoji.ttc", // macOS system emoji font
51+
"/Library/Fonts/NotoColorEmoji.ttf", // macOS with Noto font installed
52+
"C:\\Windows\\Fonts\\NotoColorEmoji.ttf" // Windows with Noto font installed
4653
};
4754

4855
class Outline
@@ -707,8 +714,13 @@ private static StringComparison GetStringComparison()
707714
: StringComparison.Ordinal;
708715
}
709716

710-
// Try to load an emoji font from the environment variable or known paths
711-
// Returns the path of the loaded font, or null if no font was loaded
717+
/// <summary>
718+
/// Try to load an emoji font from the environment variable or known system paths.
719+
/// When emoji characters like 👍 are present in the document, this ensures they
720+
/// are properly embedded in the PDF.
721+
/// </summary>
722+
/// <param name="builder">The PDF document builder</param>
723+
/// <returns>The path of the loaded font, or null if no font was loaded</returns>
712724
private static string? TryLoadEmojiFont(PdfDocumentBuilder builder)
713725
{
714726
// First, check if a font is specified via environment variable

0 commit comments

Comments
 (0)