[]
フォント設定機能を使用すると、さまざまなプラットフォームでページ、RDL、およびセクションレポート(クロスプラットフォーム互換モード)で使用するフォントを構成できます。
type=note
メモ:デフォルトフォント設定より、カスタムフォント設定が優先されます。
次のサンプルコードのように、Windowsフォーム用のビューワとJSビューワでFontResolverプロパティを指定する必要があります。
app.UseReporting(config => {
config.FontResolver = ...
config.UseFileStore(ResourcesRootDirectory)
});
インストールせずにすべてのプラットフォームでプレビューおよびエクスポートできるようにフォントを構成できます。
public sealed class WindowsFontResolver : GrapeCity.ActiveReports.IFontResolver
{
static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection();
static WindowsFontResolver()
{
GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(_fonts, true);
_fonts.DefaultFont = _fonts.FindFamilyName("Arial");
}
public static GrapeCity.ActiveReports.IFontResolver Instance = new WindowsFontResolver();
private WindowsFontResolver() { }
GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
{
var fonts = new GrapeCity.Documents.Text.FontCollection();
fonts.Add(_fonts.FindFamilyName(familyName, isBold, isItalic) ?? _fonts.DefaultFont);
GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateEudcLinks(fonts);
return fonts;
}
}
public sealed class DirectoryFontResolver : GrapeCity.ActiveReports.IFontResolver
{
static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection();
static DirectoryFontResolver()
{を参照してください。
// https://developers.redhat.com/blog/2018/11/07/dotnet-special-folder-api-linux/ を参照してください。
_fonts.RegisterDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts));
_fonts.DefaultFont = _fonts.FindFamilyName("Arial");
}
public static GrapeCity.ActiveReports.IFontResolver Instance = new DirectoryFontResolver();
private DirectoryFontResolver() { }
GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
{
var fonts = new GrapeCity.Documents.Text.FontCollection();
var font = _fonts.FindFamilyName(familyName, isBold, isItalic);
if (font != null) fonts.Add(font);
fonts.Add(_fonts.DefaultFont);
return fonts;
}
}
ActiveReports.configファイルでカスタムフォントを設定する方法については、「ActiveReportsの構成ファイル」を参照してください。
1つのフォントを別のフォントにリンクする(たとえば、EUDCフォントをインストールされているフォントにリンクする)には、次のコードのように、ドキュメントAPI(GcImagingおよびGcPdf)を使用できます。
GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(null, true);
var fonts = new System.Collections.Generic.List();
GrapeCity.Documents.Text.FontCollection.SystemFonts.SelectByFamilyName("MS UI Gothic", fonts);
if (fonts.Count > 0)
{
var eudcFonts = new GrapeCity.Documents.Text.FontCollection();
using (var stream = new System.IO.FileStream(@"C:\EudcFonts\DFHSG3J.tte", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
eudcFonts.LoadFonts(stream);
foreach (var font in fonts)
{
font.ClearEudcFontLinks();
foreach (var eudcFont in eudcFonts) font.AddEudcFont(eudcFont);
}
}