Skip to content

Commit

Permalink
Fix/1181 cyrillic print support (#1189)
Browse files Browse the repository at this point in the history
* Now using Roboto as font when printing

* Updated font naming
  • Loading branch information
Hallbergs committed Sep 27, 2022
1 parent fc716c3 commit 3a56145
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion new-client/src/plugins/Print/PrintModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import TileLayer from "ol/layer/Tile";
import TileWMS from "ol/source/TileWMS";
import ImageWMS from "ol/source/ImageWMS";

import { ROBOTO_NORMAL } from "./constants";

export default class PrintModel {
constructor(settings) {
this.map = settings.map;
Expand Down Expand Up @@ -399,7 +401,6 @@ export default class PrintModel {
) => {
const lengthText = this.getLengthText(scaleBarLengthMeters);
pdf.setFontSize(8);
pdf.setFont("helvetica", "bold");
pdf.setTextColor(color);
pdf.setLineWidth(0.25);
pdf.text(
Expand Down Expand Up @@ -885,6 +886,23 @@ export default class PrintModel {
this.addedLayers = new Set();
};

// Adds fonts needed to properly render necessary characters. (The default jsPDF fonts does not support all characters).
// Also enables a font (in the future we could provide a possibility for the user to select font).
setupFonts = (pdf, font = "ROBOTO_NORMAL") => {
// First we'll add the available fonts
pdf.addFileToVFS("roboto-normal.ttf", ROBOTO_NORMAL);
pdf.addFont("roboto-normal.ttf", "roboto-normal", "normal");
// Then we'll set the font we want to use now. (The switch below is unnecessary but
// added for possible future use cases).
switch (font) {
case "ROBOTO_NORMAL":
pdf.setFont("roboto-normal");
break;
default:
break;
}
};

print = (options) => {
const format = options.format;
const orientation = options.orientation;
Expand Down Expand Up @@ -974,6 +992,9 @@ export default class PrintModel {
compress: true,
});

// Make sure to add necessary fonts and enable the font we want to use.
this.setupFonts(pdf, "ROBOTO");

// Add our map canvas to the PDF, start at x/y=0/0 and stretch for entire width/height of the canvas
pdf.addImage(mapCanvas, "JPEG", 0, 0, dim[0], dim[1]);

Expand Down
1 change: 1 addition & 0 deletions new-client/src/plugins/Print/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ROBOTO_NORMAL } from "./roboto-normal";
2 changes: 2 additions & 0 deletions new-client/src/plugins/Print/constants/roboto-normal.js

Large diffs are not rendered by default.

0 comments on commit 3a56145

Please sign in to comment.