@@ -34,23 +34,6 @@ namespace Docfx.Pdf;
3434static class PdfBuilder
3535{
3636 private static readonly SearchValues < char > InvalidPathChars = SearchValues . Create ( Path . GetInvalidPathChars ( ) ) ;
37-
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>
43- private const string EmojiFontPathEnvVar = "DOCFX_PDF_EMOJI_FONT" ;
44-
45- // Common paths for Noto Color Emoji font on various systems
46- private static readonly string [ ] KnownEmojiPaths = new [ ]
47- {
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
53- } ;
5437
5538 class Outline
5639 {
@@ -373,14 +356,6 @@ static async Task CreatePdf(
373356 using var builder = new PdfDocumentBuilder ( output ) ;
374357
375358 builder . DocumentInformation = new ( ) { Producer = producer } ;
376-
377- // Try to load emoji fonts
378- string ? emojiFontPath = TryLoadEmojiFont ( builder ) ;
379- if ( ! string . IsNullOrEmpty ( emojiFontPath ) )
380- {
381- builder . DocumentInformation . Keywords += $ " emoji-font: { Path . GetFileName ( emojiFontPath ) } ";
382- }
383-
384359 builder . Bookmarks = CreateBookmarks ( outline . items ) ;
385360
386361 await MergePdf ( ) ;
@@ -419,7 +394,7 @@ async Task MergePdf()
419394 {
420395 var pageNumber = 0 ;
421396 var font = builder . AddStandard14Font ( UglyToad . PdfPig . Fonts . Standard14Fonts . Standard14Font . Helvetica ) ;
422-
397+
423398 foreach ( var ( url , node ) in pages )
424399 {
425400 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -713,49 +688,4 @@ private static StringComparison GetStringComparison()
713688 ? StringComparison . OrdinalIgnoreCase
714689 : StringComparison . Ordinal ;
715690 }
716-
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>
724- private static string ? TryLoadEmojiFont ( PdfDocumentBuilder builder )
725- {
726- // First, check if a font is specified via environment variable
727- var emojiFontPath = Environment . GetEnvironmentVariable ( EmojiFontPathEnvVar ) ;
728-
729- // If no environment variable is set, try the known emoji font paths
730- if ( string . IsNullOrEmpty ( emojiFontPath ) )
731- {
732- foreach ( var path in KnownEmojiPaths )
733- {
734- if ( File . Exists ( path ) )
735- {
736- emojiFontPath = path ;
737- break ;
738- }
739- }
740- }
741-
742- // Try to load the font if we found a path
743- if ( ! string . IsNullOrEmpty ( emojiFontPath ) && File . Exists ( emojiFontPath ) )
744- {
745- try
746- {
747- // Load the font as a TrueType font
748- builder . AddTrueTypeFont ( File . ReadAllBytes ( emojiFontPath ) ) ;
749- Logger . LogInfo ( $ "Loaded emoji font from { emojiFontPath } ") ;
750- return emojiFontPath ;
751- }
752- catch ( Exception ex )
753- {
754- // Log error but continue with standard fonts if emoji font loading fails
755- Logger . LogWarning ( $ "Failed to load emoji font from { emojiFontPath } : { ex . Message } ") ;
756- }
757- }
758-
759- return null ;
760- }
761691}
0 commit comments