Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3588,7 +3588,7 @@ class PartialEvaluator {
if (properties.composite) {
// CIDSystemInfo helps to match CID to glyphs
const cidSystemInfo = dict.get("CIDSystemInfo");
if (cidSystemInfo instanceof Dict) {
if (cidSystemInfo instanceof Dict && !properties.cidSystemInfo) {
properties.cidSystemInfo = {
registry: stringToPDFString(cidSystemInfo.get("Registry")),
ordering: stringToPDFString(cidSystemInfo.get("Ordering")),
Expand Down Expand Up @@ -3670,6 +3670,51 @@ class PartialEvaluator {
baseEncodingName = null;
}

// Ignore incorrectly specified WinAnsiEncoding for non-embedded CJK fonts
// (fixes issue20489). Some chinese fonts often have WinAnsiEncoding in the
// PDF even though they should use Identity-H or GB-EUC-H encoding.
if (
baseEncodingName === "WinAnsiEncoding" &&
nonEmbeddedFont &&
properties.name?.charCodeAt(0) >= 0xb7
) {
const fontName = properties.name;
// This list is built from some names from Pdfium and mupdf:
// - https://pdfium.googlesource.com/pdfium/+/master/core/fpdfapi/font/cpdf_font.cpp#41
// - https://fossies.org/linux/mupdf/source/pdf/pdf-font.c#l_820
const chineseFontNames = [
"\xCB\xCE\xCC\xE5", // SimSun
"\xBA\xDA\xCC\xE5", // SimHei
"\xBF\xAC\xCC\xE5", // SimKai
"\xB7\xC2\xCB\xCE", // SimFang
"\xBF\xAC\xCC\xE5_GB2312", // SimKai
"\xB7\xC2\xCB\xCE_GB2312", // SimFang
"\xC1\xA5\xCA\xE9", // SimLi
"\xD0\xC2\xCB\xCE", // SimSun
];

// Check for common Chinese font names and their GBK-encoded equivalents
// (which may appear as Latin-1 when incorrectly decoded).
if (chineseFontNames.includes(fontName)) {
baseEncodingName = null;
properties.defaultEncoding = "Adobe-GB1-UCS2";
properties.composite = true;
properties.cidEncoding = Name.get("GBK-EUC-H");
const cMap = await CMapFactory.create({
encoding: properties.cidEncoding,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null,
});
properties.cMap = cMap;
properties.vertical = properties.cMap.vertical;
properties.cidSystemInfo = {
registry: "Adobe",
ordering: "GB1",
supplement: 0,
};
}
}

if (baseEncodingName) {
properties.defaultEncoding = getEncoding(baseEncodingName);
} else {
Expand Down
58 changes: 58 additions & 0 deletions src/core/font_substitutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,64 @@ const substitutionMap = new Map([
alias: "Wingdings",
},
],
[
"\xCB\xCE\xCC\xE5",
{
local: ["SimSun", "SimSun Regular", "NSimSun"],
style: NORMAL,
ultimate: "serif",
},
],
[
"\xBA\xDA\xCC\xE5",
{
local: ["SimHei", "SimHei Regular"],
style: NORMAL,
ultimate: "sans-serif",
},
],
[
"\xBF\xAC\xCC\xE5",
{
local: ["KaiTi", "SimKai", "SimKai Regular"],
style: NORMAL,
ultimate: "sans-serif",
},
],
[
"\xB7\xC2\xCB\xCE",
{
local: ["FangSong", "SimFang", "SimFang Regular"],
style: NORMAL,
ultimate: "serif",
},
],
[
"\xBF\xAC\xCC\xE5_GB2312",
{
alias: "\xBF\xAC\xCC\xE5",
},
],
[
"\xB7\xC2\xCB\xCE_GB2312",
{
alias: "\xB7\xC2\xCB\xCE",
},
],
[
"\xC1\xA5\xCA\xE9",
{
local: ["SimLi", "SimLi Regular"],
style: NORMAL,
ultimate: "serif",
},
],
[
"\xD0\xC2\xCB\xCE",
{
alias: "\xCB\xCE\xCC\xE5",
},
],
]);

const fontAliases = new Map([["Arial-Black", "ArialBlack"]]);
Expand Down
76 changes: 65 additions & 11 deletions src/display/pattern_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,51 @@ class RadialAxialShadingPattern extends BaseShadingPattern {
this.matrix = null;
}

_createGradient(ctx) {
isOriginBased() {
return (
this._p0[0] === 0 &&
this._p0[1] === 0 &&
(!this.isRadial() || (this._p1[0] === 0 && this._p1[1] === 0))
);
}

isRadial() {
return this._type === "radial";
}

_createGradient(ctx, transform = null) {
let grad;
let firstPoint = this._p0;
let secondPoint = this._p1;
if (transform) {
firstPoint = firstPoint.slice();
secondPoint = secondPoint.slice();
Util.applyTransform(firstPoint, transform);
Util.applyTransform(secondPoint, transform);
}
if (this._type === "axial") {
grad = ctx.createLinearGradient(
this._p0[0],
this._p0[1],
this._p1[0],
this._p1[1]
firstPoint[0],
firstPoint[1],
secondPoint[0],
secondPoint[1]
);
} else if (this._type === "radial") {
let r0 = this._r0;
let r1 = this._r1;
if (transform) {
const scale = new Float32Array(2);
Util.singularValueDecompose2dScale(transform, scale);
r0 *= scale[0];
r1 *= scale[0];
}
grad = ctx.createRadialGradient(
this._p0[0],
this._p0[1],
this._r0,
this._p1[0],
this._p1[1],
this._r1
firstPoint[0],
firstPoint[1],
r0,
secondPoint[0],
secondPoint[1],
r1
);
}

Expand All @@ -100,6 +128,32 @@ class RadialAxialShadingPattern extends BaseShadingPattern {
getPattern(ctx, owner, inverse, pathType) {
let pattern;
if (pathType === PathType.STROKE || pathType === PathType.FILL) {
if (this.isOriginBased()) {
let transf = Util.transform(inverse, owner.baseTransform);
if (this.matrix) {
transf = Util.transform(transf, this.matrix);
}
const precision = 1e-3;
const n1 = Math.hypot(transf[0], transf[1]);
const n2 = Math.hypot(transf[2], transf[3]);
const ps = (transf[0] * transf[2] + transf[1] * transf[3]) / (n1 * n2);
if (Math.abs(ps) < precision) {
// The images of the basis vectors are orthogonal.
if (this.isRadial()) {
// If the images of the basis vectors are a square then the
// circles are transformed to circles and we can use a gradient
// directly.
if (Math.abs(n1 - n2) < precision) {
return this._createGradient(ctx, transf);
}
} else {
// The rectangles are transformed to rectangles and we can use a
// gradient directly.
return this._createGradient(ctx, transf);
}
}
}

const ownerBBox = owner.current.getClippedPathBoundingBox(
pathType,
getCurrentTransform(ctx)
Expand Down
Loading
Loading