Skip to content

Commit 12fb85b

Browse files
Copilotyufeih
andcommitted
Revert code changes and install fonts-noto-color-emoji in CI
Co-authored-by: yufeih <511355+yufeih@users.noreply.github.com>
1 parent 8b0edbf commit 12fb85b

File tree

6 files changed

+16
-72
lines changed

6 files changed

+16
-72
lines changed

.github/actions/build/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ runs:
1313
9.x
1414
8.x
1515
16+
- name: Install fonts-noto-color-emoji package (Linux only)
17+
if: runner.os == 'Linux'
18+
shell: bash
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y fonts-noto-color-emoji
22+
1623
- run: npm ci
1724
shell: bash
1825
working-directory: templates

.github/workflows/snapshot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
ref: ${{ github.ref_name }}
2525
lfs: true
2626

27+
# Install fonts-noto-color-emoji for emoji support in PDF generation
28+
- name: Install fonts-noto-color-emoji
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y fonts-noto-color-emoji
32+
2733
# Build projects
2834
- uses: ./.github/actions/build
2935

Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project>
22
<PropertyGroup>
33
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(DOCFX_PREVIEW_BUILD)' == 'true'">net8.0;net10.0</TargetFrameworks>
56
<LangVersion>Preview</LangVersion>
67
<ImplicitUsings>enable</ImplicitUsings>
78
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>

dotnet-install.sh

Whitespace-only changes.

dotnet-sdk.tar.gz

Whitespace-only changes.

src/Docfx.App/PdfBuilder.cs

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,6 @@ namespace Docfx.Pdf;
3434
static 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

Comments
 (0)