[{"id":"ffec8bd3-7aae-4594-9410-30d8f75cd1d8","tags":[]},{"id":"7f87098b-cd80-42f7-b7c9-7ae079678a7d","tags":[]},{"id":"ede32062-2e96-44f1-91be-e72dd30ff38b","tags":[]},{"id":"2ac89cad-34cb-48d7-8d48-3d6fd8cf8a6d","tags":[]},{"id":"f95a1044-eee9-4cc3-ad34-a6abc40b7147","tags":[]},{"id":"a279e56b-9235-4470-a356-4e399491a489","tags":[]},{"id":"02619332-218d-4596-a566-4d10101c2fea","tags":[]},{"id":"b8d38a00-4d21-48aa-97d8-897743942525","tags":[]},{"id":"5ab75a14-d8aa-434a-91b4-3a46c924cd43","tags":[]},{"id":"7e3bfaec-bbcf-44b0-b1e0-23fa8938b378","tags":[]},{"id":"653a143f-a896-4baf-973f-8e9ff7d1caeb","tags":[]},{"id":"e6d68977-a270-4159-98f6-e0fed88b9b9d","tags":[]},{"id":"2c9104de-dfae-4165-a88c-3c702a7498b9","tags":[]},{"id":"67b4ece0-e32a-4778-bf78-39885d155a08","tags":[]},{"id":"cb1e72ed-746e-4f16-9ddc-ca4399a854ed","tags":[]},{"id":"7e5f6b8f-e289-4005-a9f1-f2fd24314969","tags":[]},{"id":"0d965fbd-0dba-4f62-a51d-39d9d1b89801","tags":[]},{"id":"16ef7359-484c-49f7-b00e-7a33904c6766","tags":[]},{"id":"44f82afe-5243-44ad-9514-3efce2f99e92","tags":[]},{"id":"41be4710-f6ef-40f7-a217-760ca7ac6d8d","tags":[]},{"id":"fe917819-bfd3-4463-a493-308aae3c0466","tags":[]},{"id":"85372212-6e12-4968-bff8-f1de2b53dacb","tags":[]},{"id":"12f32f30-f5f0-4a05-bf43-f6a4fd759483","tags":[]},{"id":"b0d4f051-46f7-4d39-90c4-10ca9a143e6d","tags":[]},{"id":"78217127-2f7c-4c2a-b1e0-a6462c036af1","tags":[]},{"id":"74fa9231-f7cc-42d2-80b9-e9e345120845","tags":[]},{"id":"a9e33769-b100-486f-88c9-75826b6a641f","tags":[]},{"id":"7c1ad13d-649f-4b90-9929-6567e9cb70ce","tags":[]},{"id":"e84b6f40-5d38-4e83-8ed8-42b3b192effc","tags":[]},{"id":"2003fa15-8ff1-463f-b443-b07cdfddda15","tags":[]},{"id":"94428a30-1b4f-408f-b13c-a91956e8bc8b","tags":[]},{"id":"b4d5cb90-b917-4abb-9d72-dc8732531d6d","tags":[]},{"id":"cbf4614f-4e01-4057-977d-c09f6027773a","tags":[]},{"id":"4f0464ba-a76b-4420-acf9-6b301fe92eb5","tags":[]},{"id":"de092a26-237a-4b4a-a26b-219a08d58290","tags":[]},{"id":"5085c479-6416-4cb4-9b03-03e3cb5dfb49","tags":[]},{"id":"fa57bedb-7a35-43df-9bb0-11f75cb6b036","tags":[]},{"id":"0d296f98-2882-4f36-99ca-593d81c1ea2c","tags":[]},{"id":"8f8d76db-fcf1-4614-a69d-91fcaa8e4c06","tags":[]},{"id":"2d045589-5bdf-4ea9-9daf-79f0737f1a7d","tags":[]},{"id":"a1cb9471-cc43-421e-a27c-73a77ed2c076","tags":[]},{"id":"ba0d2930-0bc2-41e7-bfb6-f670ba248346","tags":[]},{"id":"d9001f98-5ff3-4daa-ad2b-ae1871d80280","tags":[]},{"id":"8aa00408-e544-4f85-af0c-844a89483b71","tags":[]},{"id":"ea9401b1-388f-4801-9a1e-c61c241eb266","tags":[]},{"id":"4013df1a-026b-4e3e-9a55-2d9aa67ae595","tags":[]},{"id":"15925a79-6794-4fd3-a1d3-1140dbb7c895","tags":[]},{"id":"602c67a6-e96b-40b4-9a3e-58d3a025ee79","tags":[]},{"id":"628a0d59-3012-4486-87ee-327769c3aade","tags":[]},{"id":"43174189-d292-441e-96d4-671cf41684af","tags":[]},{"id":"5bc3527a-fc3e-437b-b5b7-00de4df2a2e5","tags":[]},{"id":"95724458-648d-4e53-a7a0-1337147ba3f4","tags":[]},{"id":"718d9115-3748-4484-8de8-3ced6e6c9700","tags":[]},{"id":"96ee753e-323d-4c1d-9eef-cc6bbc49cfc5","tags":[]},{"id":"60915523-8425-4684-9091-aa61a5e128f8","tags":[]},{"id":"026e2b9d-c68b-4a6f-bcf3-81c9e561f72c","tags":[]},{"id":"8cd4c6c2-43c3-4eee-865e-7ff204686d95","tags":[]},{"id":"bafbd30c-cdea-48c5-ae61-35ca286807ae","tags":[]},{"id":"332d456f-ad33-4575-bc27-961f08e6e91a","tags":[]},{"id":"3d6a25a2-259b-4717-949d-ffd746bbd16f","tags":[]},{"id":"d9eafb77-36ca-4e7b-b5c0-a6af25f7688a","tags":[]},{"id":"1f4bdca8-96a1-4cd6-a28e-36f00c37f2b8","tags":[]},{"id":"cc6bd783-e124-4778-b33b-8d8bd684174b","tags":[]},{"id":"40c3a8e6-1851-4a07-92b5-e5dbe79bd947","tags":[]},{"id":"3e93722a-922b-4e74-b888-60aa9711e910","tags":[]},{"id":"330219a6-2d62-4311-b0f0-2a63e6494f52","tags":[]},{"id":"303ede1f-f050-4e6a-81f3-57f5fea3f023","tags":[]},{"id":"8dac0e10-8c23-4173-a81c-0ccc62ff2851","tags":[]},{"id":"5d34d850-ab62-411e-87c6-ae34b948837c","tags":[]},{"id":"a17002a8-d526-4bab-adba-1225ecefa9c2","tags":[]},{"id":"6565eed5-a7f1-4b4b-8e79-b1b3211e2844","tags":[]},{"id":"43db06fc-f088-456d-b629-da070ced97c4","tags":[]},{"id":"23cd309a-4aa2-42a6-9a07-93fc70cbcd4c","tags":[]},{"id":"a355851a-9db9-478e-a342-276cdf963ab0","tags":[]},{"id":"0ca21ed4-1c3a-454c-9fa9-ace10bb631f7","tags":[]},{"id":"9b4f0622-c977-419f-b7fa-08a06a822378","tags":[]},{"id":"9db64270-eb0d-4c10-a3bd-99019a61d88d","tags":[]},{"id":"deec10d3-1cdd-4cf8-9bf8-9dc83f5005c2","tags":[]},{"id":"840c76dd-1003-4004-9aed-2bb0f7f64bcf","tags":[]},{"id":"a896ba47-426f-40a9-b640-39c5ba2e833e","tags":[]},{"id":"08e827cd-7c35-4891-91eb-3dcd38b24497","tags":[]},{"id":"c1573d04-8739-4293-99c6-c67af3c268b6","tags":[]},{"id":"3bd2cf00-2478-4c5f-877d-c43d4055b6d5","tags":[]},{"id":"a2575396-489d-49ce-a64e-671618389234","tags":[]},{"id":"da7309ca-78d5-4ab0-bacd-bd3efb37052a","tags":[]},{"id":"4fa7027e-e3b8-4558-a6a2-3d82194aa902","tags":[]},{"id":"123eb75a-7345-4b9f-86d4-d9c5e26e4f23","tags":[]},{"id":"5be2a877-4210-4df5-b725-bcd0e4fff62a","tags":[]},{"id":"47369ff7-3c58-4bbc-95e1-731d5c860b6a","tags":[]},{"id":"09135abc-177b-40a8-b7dd-c07e17550524","tags":[]},{"id":"5d7d6a4c-7700-4677-b9de-1a2f61fc1b63","tags":[]},{"id":"f7a66b21-bc48-4605-861e-836d79687cd5","tags":[]},{"id":"47f3215b-40b9-48e4-a12b-a4ba57b4f5f9","tags":[]},{"id":"3384d245-3058-4404-986e-6bd7b5c2f98d","tags":[]},{"id":"0cd35bb9-2405-4276-a2d7-c2b2c185212c","tags":[]},{"id":"2546b319-a2ef-46ad-870e-49347241fd44","tags":[]},{"id":"ec2d5efc-2644-4822-a21c-896f3417c2cc","tags":[]},{"id":"2ff2e2d2-9733-44e7-a4a4-f730afef9cc1","tags":[]},{"id":"8dcf63fe-80b1-4c77-967a-74924e3fab78","tags":[]},{"id":"f3eae03a-f6a8-4d1d-89ff-e03d36b1e4f3","tags":[]},{"id":"7369af56-7540-4fa7-91ad-1aaafb9ce815","tags":[]},{"id":"fd21e178-20d8-4d8c-be94-7fc3427d67cc","tags":[]},{"id":"28ca9a0a-9c8d-41fe-a294-4f151b518c95","tags":[]},{"id":"bd1628a0-f262-443f-bebf-e01742ee14d8","tags":[]},{"id":"abb90f39-6fd8-4f77-9c21-f7deadebac6a","tags":[]},{"id":"21e95400-7799-43bd-8892-b671d5ee2ed6","tags":[]},{"id":"3f805309-bfc4-41b5-bae2-96531e437b1e","tags":[]},{"id":"50ee4772-5f4a-489e-bb4c-49384cb6603b","tags":[]},{"id":"b3873b71-a23a-4dda-baa5-c0a76c75efeb","tags":[]},{"id":"be07849b-cec2-4116-b2f3-94f78b5673f7","tags":[]},{"id":"e7b17b5c-48f0-48b7-96c8-bdfb1e496075","tags":[]},{"id":"ee0891ea-23db-48ec-951a-3b8795e1d343","tags":[]},{"id":"cff30e38-eb6c-4e5d-8b86-8925ada9ba8b","tags":[]},{"id":"4b211280-ff30-4820-9f7c-f11845c23742","tags":[]},{"id":"13ca98f6-307a-42cf-8866-a88987905597","tags":[]}]
        
(Showing Draft Content)

字体配置

所有ActiveReportsJS组件都基于Web浏览器环境来运行。

通常情况下,报表由文本内容组成,浏览器通过使用glyphs来渲染的字体形状。字体资源包含将字符编码映射到代表这些字符的字形的信息。因此,浏览器需要访问字体资源,才能够按照预期显示文本。


ActiveReportsJS 中的所有文本项都具有几种字体属性,包括

  • 字体: 字体ID 如 Arial, Calibri, 或 Times New Roman

  • 字体样式: 正常 或 斜体

  • 字体粗细: 较细,细体,正常,适中,粗体,较粗

这三个属性的独特组合称为“字体”。字体系列通常由多个字体组成,通常由单独的文件表示。例如,以下是Windows 系统中Arial字体系列文件夹的屏幕截图:




当 ActiveReportsJS 渲染报表时,它将这些字体属性翻译成font-family, font-stylefont-stylefont-weightfont-weightCSS样式属性,并依靠浏览器来解析相关的字体资源,提取所需的字形。浏览器有两种方式来访问字体资源它们可能安装在浏览器运行的系统中,也可能是可下载的。


使用可下载的字体资源易于维护;所有浏览器都支持它,并且它保证了在所有环境中文本内容的一致输出。此外,ActiveReportsJS PDF 导出需要注册字体,因为它将其子集嵌入到PDF文档中。因此,确保所有环境中报表输出一致的最佳方法是配置ActiveReportsJS组件以访问可下载的字体资源。本文提供了实现该目标的分步指南。


首先,决定在报表中使用哪些字体系列。它可以是标准字体,如Arial、Times New Roman或Helvetica。也可以是一种或多种网络字体。我们在演示网站示例报表中使用 Montserrat 字体。在任何情况下,请确保你拥有字体的所有文件。ActiveReportsJS支持以下字体格式。

字体格式

文件扩展名

注意

WOFF 1.0 (Web 开放字体格式)

*.woff


WOFF 2.0 (Web 开放字体格式)

*.woff2

IE11 不支持

TrueType

*.ttf


OpenType

*.ttf, *.otf


配置桌面设计器字体

您可以在以下位置找到独立的报表设计器字体配置。

  • Windows : C:\Users\您的计算机名\AppData\Roaming\ActiveReportsJS Designer

  • MacOS: ~/Library/Application Support/ActiveReportsJS Designer/fontsConfig.json

  • Linux: ~/.config/ActivereportsJS Designer/fontsConfig.json

创建 Fonts文件夹,并将所有需要的字体资源文件拷贝到该文件夹下面。


然后打开 fontsConfig.json 文件 ,该文件包含报表文本内容的涉及的字体描述符。在 path 属性中, 指定到Fonts目录的父文件夹的绝对路径。替换 descriptors 默认项。每个描述符都包含以下属性:

属性名称

描述

注意

name

字体名称

"Arial" 或 "Times New Roman"

style

字体样式

"normal" 或 "italic"

weight

字体粗细

建议使用100到900之间的数值。 参考 CSS 说明

source

字体文件的相对路径

例如, "Fonts/Calibri/calibri.ttf"

例如, 使用 Montserrat 字体, 可以添加以下信息

fontsConfig.json中"descriptors" 字段示例

{
    "name": "Montserrat",
    "weight": "100",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-Thin.ttf"
},
{
    "name": "Montserrat",
    "weight": "100",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-ThinItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "200",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-ExtraLight.ttf"
},
{
    "name": "Montserrat",
    "weight": "200",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-ExtraLightItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "300",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-Light.ttf"
},
{
    "name": "Montserrat",
    "weight": "300",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-LightItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "400",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-Regular.ttf"
},
{
    "name": "Montserrat",
    "weight": "400",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-Italic.ttf"
},
{
    "name": "Montserrat",
    "weight": "500",
    "source": "Fonts/Montserrat/Montserrat-Medium.ttf"
},
{
    "name": "Montserrat",
    "weight": "500",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-MediumItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "600",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-SemiBold.ttf"
},
{
    "name": "Montserrat",
    "weight": "600",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-SemiBoldItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "700",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-Bold.ttf"
},
{
    "name": "Montserrat",
    "weight": "700",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-BoldItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "800",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-ExtraBold.ttf"
},
{
    "name": "Montserrat",
    "weight": "800",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-ExtraBoldItalic.ttf"
},
{
    "name": "Montserrat",
    "weight": "900",
    "style": "normal",
    "source": "Fonts/Montserrat/Montserrat-Black.ttf"
},
{
    "name": "Montserrat",
    "weight": "900",
    "style": "italic",
    "source": "Fonts/Montserrat/Montserrat-BlackItalic.ttf"
}

运行桌面设计器应用程序,在报表中添加一个文本框,并确保能将字体属性设置为在fontsConfig.json文件中列举的字体之一,并且所有的字体都能正确显示。

配置基于 ActiveReportsJS 的应用程序

在报表Viewer中显示报表,将报表导出为PDF或托管报表设计器组件的应用程序应使用与为独立设计器应用程序创建的配置相同的配置。

最简单的方式是复制Fonts 文件夹和 fontsConfig.json 文件到项目的 assets 文件夹下面. 此文件夹因不同的前端框架而异。 v 示例如下:

{
    "name": "Montserrat",
    "weight": "900",
    "style": "italic",
    "source": "assets/Fonts/Montserrat/Montserrat-BlackItalic.ttf"
}  
  • Vue框架是放置在 静态 Assets文件处理

    最后,该应用程序,应该调用 FontStoreregisterFonts 方法 ,来加载fontsConfig 文件。

    该代码需要在应用程序开始展示或导出报表之前执行。注意 registerFonts 方法是个异步函数,并会返回 Promise 对象。 也可以,调用此方法的代码可以等待,直到返回Promise结果后,再在查看器组件中加载报表或导出报表。

纯 JavaScript 代码示例:

<script src="https://cdn.grapecity.com/activereportsjs/3.0.0/dist/ar-js-core.js"></script>
<script>
  GC.ActiveReports.Core.FontStore.registerFonts(
    "/resources/fontsConfig.json" // replace the URL with the actual one
  )
</script>  

Angular,React和Vue代码示例:

import { Core } from "@grapecity/activereports";
Core.FontStore.registerFonts("/assets/fontConfig.json") // replace the URL with the actual one

详细代码可参考 在线示例.

配置 Web 报表设计器

为确保报表设计器组件仅显示注册的字体, 设置 设计器实例的fontSet 属性 为registered.

相关资源