Skip to content

Commit

Permalink
Resolved #101 - Extratcted Segoe font from survey-pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Feb 11, 2022
1 parent 5ec0f8e commit 65d5629
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ steps:
OverWrite: true

- script: |
npm run build_fonts
npm run build_prod
npm test
displayName: 'npm build and test'
Expand Down
5 changes: 5 additions & 0 deletions devops-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ steps:
TargetFolder: '$(Build.SourcesDirectory)/survey-pdf/node_modules/surveyjs-widgets'
OverWrite: true

- script: |
cd $(Build.SourcesDirectory)/survey-pdf
npm run build_fonts
displayName: 'build fonts'

- script: |
cd $(Build.SourcesDirectory)/survey-pdf
npm run build_prod
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"doc_update": "chmod +x ./docupdate_npm.sh && ./docupdate_npm.sh",
"build_dev": "webpack --env.buildType dev --env.platform pdf",
"build_prod": "npm run build_dev && webpack --env.buildType prod --env.platform pdf && npm run dts_clean",
"build_fonts": "webpack --config ./webpack.fonts.js --env.buildType dev && webpack --config ./webpack.fonts.js --env.buildType prod",
"dts_clean": "node dts_cleaner.js",
"lint": "eslint ./src --quiet",
"pre-push-check": "npm run lint && npm run build_prod && npm test"
Expand Down Expand Up @@ -44,7 +45,8 @@
"ts-jest": "^23.10.3",
"ts-loader": "2.3.4",
"typescript": "^4.2.2",
"webpack": "2.2.1"
"webpack": "2.2.1",
"webpack-merge": "^5.8.0"
},
"husky": {
"hooks": {
Expand Down
4 changes: 4 additions & 0 deletions release-azure-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ steps:
npm run release -- --release-as $(SurveyJSVersion)
displayName: 'npm run release with SurveyJSVersion'

- script: |
npm run build_fonts
displayName: 'build fonts'

- script: |
npm run build_prod
displayName: 'build'
Expand Down
10 changes: 7 additions & 3 deletions src/doc_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jsPDF, jsPDFOptions } from 'jspdf';
import { IHTMLRenderType } from './flat_layout/flat_html';
import { SurveyHelper } from './helper_survey';
import { LocalizableString } from 'survey-core';
import Fonts from './fonts';
// import Fonts from './fonts';
import setRadioAppearance from './jspdf_plugins/acroform';
import './jspdf_plugins/acroform.js';
import './jspdf_plugins/from_html.js';
Expand Down Expand Up @@ -57,6 +57,8 @@ export class DocOptions implements IDocOptions {
protected _format: string | number[];
protected _fontSize: number;
protected _fontName: string;
public static SEGOE_NORMAL: string;
public static SEGOE_BOLD: string;
protected _base64Normal: string = undefined;
protected _base64Bold: string = undefined;
protected _useCustomFontInHtml: boolean;
Expand Down Expand Up @@ -88,8 +90,10 @@ export class DocOptions implements IDocOptions {
this._base64Bold = options.base64Bold || options.base64Normal;
}
else if (this.fontName === 'segoe') {
this._base64Normal = Fonts.SEGOE_NORMAL;
this._base64Bold = Fonts.SEGOE_BOLD;
// this._base64Normal = Fonts.SEGOE_NORMAL;
// this._base64Bold = Fonts.SEGOE_BOLD;
this._base64Normal = DocOptions.SEGOE_NORMAL;
this._base64Bold = DocOptions.SEGOE_BOLD;
}
this._useCustomFontInHtml = options.useCustomFontInHtml && typeof options.base64Normal !== 'undefined';
this._margins = SurveyHelper.clone(options.margins);
Expand Down
7 changes: 6 additions & 1 deletion src/fonts.ts

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
"importHelpers": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"survey-pdf": [
"./src/doc_controller.ts"
]
}
},
"include": ["src/**/*.ts"]
}
}
7 changes: 4 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ module.exports = function(options) {
files: [
"survey." + options.platformPrefix + ".d.ts",
"survey." + options.platformPrefix + ".js",
"survey." + options.platformPrefix + ".min.js"
],
"survey." + options.platformPrefix + ".min.js",
"survey." + options.platformPrefix + ".fonts.js",
"survey." + options.platformPrefix + ".fonts.min.js" ],
main: mainFile,
repository: {
type: "git",
Expand Down Expand Up @@ -147,7 +148,7 @@ module.exports = function(options) {
"[name]" +
(options.buildType === "prod" ? ".min" : "") +
".js",
library: "SurveyPDF",
library: options.libraryName || "SurveyPDF",
libraryTarget: "umd",
umdNamedDefine: true
},
Expand Down
31 changes: 31 additions & 0 deletions webpack.fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

const webpackCommonConfigCreator = require("./webpack.config");
var path = require("path");
const { merge } = require("webpack-merge");
var packageJson = require("./package.json");

const config = {
entry: {
"survey.pdf.fonts": path.resolve(__dirname, "./src/fonts.ts"),
},
externals: {
"survey-pdf": {
root: "SurveyPDF",
commonjs2: "survey-pdf",
commonjs: "survey-pdf",
amd: "survey-pdf"
}
}
};

module.exports = function (options) {
options.platform = "pdf";
options.libraryName = "SurveyPdfFonts";

const mainConfig = webpackCommonConfigCreator(options);
delete mainConfig.entry["survey.pdf"];
mainConfig.plugins.shift();

return merge(mainConfig, config);
};

0 comments on commit 65d5629

Please sign in to comment.