@progress/kendo-pdfviewer-common 1.0.0-develop.2 → 1.0.0-develop.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { saveAs } from '@progress/kendo-file-saver';
2
2
  import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
3
- import { getDocument, TextLayer } from "pdfjs-dist/legacy/build/pdf.mjs";
3
+ import { getDocument, TextLayer, PixelsPerInch } from "pdfjs-dist/legacy/build/pdf.mjs";
4
4
  import { LinkAnnotation } from './annotations';
5
5
  import { createElement, scrollToPage } from './common/dom';
6
6
  export { createElement, scrollToPage };
@@ -90,6 +90,10 @@ export const loadPDF = (options) => {
90
90
  const params = getDocumentParameters(options);
91
91
  const { dom, zoom, done, error, rootElement } = options;
92
92
  const loadOnDemandPageSize = options.loadOnDemandPageSize || 2;
93
+ dom.style.setProperty('--scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
94
+ dom.style.setProperty('--total-scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
95
+ dom.style.setProperty('--scale-round-x', '1px');
96
+ dom.style.setProperty('--scale-round-y', '1px');
93
97
  getDocument(params)
94
98
  .promise.then((pdfDoc) => {
95
99
  const pages = [];
@@ -131,6 +135,10 @@ export const reloadDocument = (params) => {
131
135
  const { pdfDoc, zoom, dom, done, error, loadOnDemand, rootElement } = params;
132
136
  const pages = [];
133
137
  let currentPageIndex = 0;
138
+ dom.style.setProperty('--scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
139
+ dom.style.setProperty('--total-scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
140
+ dom.style.setProperty('--scale-round-x', '1px');
141
+ dom.style.setProperty('--scale-round-y', '1px');
134
142
  // Save the index of the current page in view before we reload the document.
135
143
  if (loadOnDemand && rootElement) {
136
144
  currentPageIndex = currentPage(rootElement);
@@ -250,8 +258,13 @@ export const renderPage = (page, emptyPage, error) => {
250
258
  container: textLayer,
251
259
  viewport: viewport
252
260
  }).render().then(() => {
253
- textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
254
- textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
261
+ // Directly assign the pre-calculated pt dimensions.
262
+ // A px→pt text replacement leaves --total-scale-factor (= zoom * PDF_TO_CSS_UNITS,
263
+ // correct for CSS-px font sizes) multiplying CSS pt values, making the layer
264
+ // ~33% too wide. Assigning styles.width/height (= raw_page_width * zoom pt)
265
+ // keeps font-size calculations intact while matching the page element exactly.
266
+ textLayer.style.width = styles.width;
267
+ textLayer.style.height = styles.height;
255
268
  const rotation = textLayer.getAttribute('data-main-rotation') || '0';
256
269
  if (transforms[rotation]) {
257
270
  textLayer.style.transform = transforms[rotation];
@@ -1,6 +1,6 @@
1
1
  import { saveAs } from '@progress/kendo-file-saver';
2
2
  import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
3
- import { getDocument, TextLayer } from "pdfjs-dist/legacy/build/pdf.mjs";
3
+ import { getDocument, TextLayer, PixelsPerInch } from "pdfjs-dist/legacy/build/pdf.mjs";
4
4
  import { LinkAnnotation } from './annotations';
5
5
  import { createElement, scrollToPage } from './common/dom';
6
6
  export { createElement, scrollToPage };
@@ -90,6 +90,10 @@ export const loadPDF = (options) => {
90
90
  const params = getDocumentParameters(options);
91
91
  const { dom, zoom, done, error, rootElement } = options;
92
92
  const loadOnDemandPageSize = options.loadOnDemandPageSize || 2;
93
+ dom.style.setProperty('--scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
94
+ dom.style.setProperty('--total-scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
95
+ dom.style.setProperty('--scale-round-x', '1px');
96
+ dom.style.setProperty('--scale-round-y', '1px');
93
97
  getDocument(params)
94
98
  .promise.then((pdfDoc) => {
95
99
  const pages = [];
@@ -131,6 +135,10 @@ export const reloadDocument = (params) => {
131
135
  const { pdfDoc, zoom, dom, done, error, loadOnDemand, rootElement } = params;
132
136
  const pages = [];
133
137
  let currentPageIndex = 0;
138
+ dom.style.setProperty('--scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
139
+ dom.style.setProperty('--total-scale-factor', String(zoom * PixelsPerInch.PDF_TO_CSS_UNITS));
140
+ dom.style.setProperty('--scale-round-x', '1px');
141
+ dom.style.setProperty('--scale-round-y', '1px');
134
142
  // Save the index of the current page in view before we reload the document.
135
143
  if (loadOnDemand && rootElement) {
136
144
  currentPageIndex = currentPage(rootElement);
@@ -250,8 +258,13 @@ export const renderPage = (page, emptyPage, error) => {
250
258
  container: textLayer,
251
259
  viewport: viewport
252
260
  }).render().then(() => {
253
- textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
254
- textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
261
+ // Directly assign the pre-calculated pt dimensions.
262
+ // A px→pt text replacement leaves --total-scale-factor (= zoom * PDF_TO_CSS_UNITS,
263
+ // correct for CSS-px font sizes) multiplying CSS pt values, making the layer
264
+ // ~33% too wide. Assigning styles.width/height (= raw_page_width * zoom pt)
265
+ // keeps font-size calculations intact while matching the page element exactly.
266
+ textLayer.style.width = styles.width;
267
+ textLayer.style.height = styles.height;
255
268
  const rotation = textLayer.getAttribute('data-main-rotation') || '0';
256
269
  if (transforms[rotation]) {
257
270
  textLayer.style.transform = transforms[rotation];
package/dist/npm/utils.js CHANGED
@@ -98,6 +98,10 @@ const loadPDF = (options) => {
98
98
  const params = getDocumentParameters(options);
99
99
  const { dom, zoom, done, error, rootElement } = options;
100
100
  const loadOnDemandPageSize = options.loadOnDemandPageSize || 2;
101
+ dom.style.setProperty('--scale-factor', String(zoom * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
102
+ dom.style.setProperty('--total-scale-factor', String(zoom * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
103
+ dom.style.setProperty('--scale-round-x', '1px');
104
+ dom.style.setProperty('--scale-round-y', '1px');
101
105
  (0, pdf_mjs_1.getDocument)(params)
102
106
  .promise.then((pdfDoc) => {
103
107
  const pages = [];
@@ -140,6 +144,10 @@ const reloadDocument = (params) => {
140
144
  const { pdfDoc, zoom, dom, done, error, loadOnDemand, rootElement } = params;
141
145
  const pages = [];
142
146
  let currentPageIndex = 0;
147
+ dom.style.setProperty('--scale-factor', String(zoom * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
148
+ dom.style.setProperty('--total-scale-factor', String(zoom * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
149
+ dom.style.setProperty('--scale-round-x', '1px');
150
+ dom.style.setProperty('--scale-round-y', '1px');
143
151
  // Save the index of the current page in view before we reload the document.
144
152
  if (loadOnDemand && rootElement) {
145
153
  currentPageIndex = (0, exports.currentPage)(rootElement);
@@ -261,8 +269,13 @@ const renderPage = (page, emptyPage, error) => {
261
269
  container: textLayer,
262
270
  viewport: viewport
263
271
  }).render().then(() => {
264
- textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
265
- textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
272
+ // Directly assign the pre-calculated pt dimensions.
273
+ // A px→pt text replacement leaves --total-scale-factor (= zoom * PDF_TO_CSS_UNITS,
274
+ // correct for CSS-px font sizes) multiplying CSS pt values, making the layer
275
+ // ~33% too wide. Assigning styles.width/height (= raw_page_width * zoom pt)
276
+ // keeps font-size calculations intact while matching the page element exactly.
277
+ textLayer.style.width = styles.width;
278
+ textLayer.style.height = styles.height;
266
279
  const rotation = textLayer.getAttribute('data-main-rotation') || '0';
267
280
  if (exports.transforms[rotation]) {
268
281
  textLayer.style.transform = exports.transforms[rotation];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@progress/kendo-pdfviewer-common",
3
3
  "description": "Kendo UI TypeScript package exporting functions for PDFViewer component",
4
- "version": "1.0.0-develop.2",
4
+ "version": "1.0.0-develop.4",
5
5
  "keywords": [
6
6
  "Kendo UI"
7
7
  ],