From 486a535587aa3e23ec382c0e0ac99c915a7d3d86 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:54:11 -0400 Subject: [PATCH 01/10] Update renderText.js --- src/render/renderText.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/renderText.js b/src/render/renderText.js index 5b58902d..4739c390 100644 --- a/src/render/renderText.js +++ b/src/render/renderText.js @@ -13,7 +13,9 @@ function insertLineBreaks(textElement, textContent) { // can't use dy attribute here since we want empty lines to take up space as well, // so we will update y manually based on font size const x = textElement.getAttribute('x'); + console.log(x); let y = Number(textElement.getAttribute('y')); + console.log(y); const size = Number(textElement.getAttribute('font-size')); for (const line of lines) { const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan'); From cd34beb544d2dd1b2c2433231a0c9de62d79e144 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:50:45 -0400 Subject: [PATCH 02/10] testing --- src/UI/text.js | 1 + src/render/appendChild.js | 1 + src/render/renderText.js | 4 ++-- src/utils/setAttributes.js | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/UI/text.js b/src/UI/text.js index 34849195..fa77ce57 100644 --- a/src/UI/text.js +++ b/src/UI/text.js @@ -66,6 +66,7 @@ function handleInputKeyup(e) { * Save a text annotation from input */ function saveText() { + console.log("check3"); let value = (input.value) ? input.value.replace(/ +$/, '') : ''; if (value.length > 0) { let clientX = parseInt(input.style.left, 10); diff --git a/src/render/appendChild.js b/src/render/appendChild.js index 9c3c0e95..9cbc2d9e 100644 --- a/src/render/appendChild.js +++ b/src/render/appendChild.js @@ -131,6 +131,7 @@ export function appendChild(svg, annotation, viewport) { child = renderPoint(annotation); break; case 'textbox': + console.log("check4"); child = renderText(annotation); break; case 'drawing': diff --git a/src/render/renderText.js b/src/render/renderText.js index 4739c390..244d020e 100644 --- a/src/render/renderText.js +++ b/src/render/renderText.js @@ -13,9 +13,8 @@ function insertLineBreaks(textElement, textContent) { // can't use dy attribute here since we want empty lines to take up space as well, // so we will update y manually based on font size const x = textElement.getAttribute('x'); - console.log(x); + console.log("check2"); let y = Number(textElement.getAttribute('y')); - console.log(y); const size = Number(textElement.getAttribute('font-size')); for (const line of lines) { const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan'); @@ -39,6 +38,7 @@ export default function renderText(a) { // Text should be rendered at 0 degrees relative to // document rotation let text = document.createElementNS('http://www.w3.org/2000/svg', 'text'); + console.log("check1") setAttributes(text, { x: a.x, y: a.y, diff --git a/src/utils/setAttributes.js b/src/utils/setAttributes.js index adc8d94d..8f17ed42 100644 --- a/src/utils/setAttributes.js +++ b/src/utils/setAttributes.js @@ -19,6 +19,7 @@ let keyCase = (key) => { * @param {Object} attributes The map of key/value pairs to use for attributes */ export default function setAttributes(node, attributes) { + console.log("check5") Object.keys(attributes).forEach((key) => { node.setAttribute(keyCase(key), attributes[key]); }); From 5b336d9576d5592e312109baa29c42be4811ae80 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Mon, 13 Jun 2022 14:23:46 -0400 Subject: [PATCH 03/10] test2 --- src/UI/text.js | 1 - src/render/appendChild.js | 1 - src/render/renderText.js | 4 ++-- src/utils/setAttributes.js | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/UI/text.js b/src/UI/text.js index fa77ce57..34849195 100644 --- a/src/UI/text.js +++ b/src/UI/text.js @@ -66,7 +66,6 @@ function handleInputKeyup(e) { * Save a text annotation from input */ function saveText() { - console.log("check3"); let value = (input.value) ? input.value.replace(/ +$/, '') : ''; if (value.length > 0) { let clientX = parseInt(input.style.left, 10); diff --git a/src/render/appendChild.js b/src/render/appendChild.js index 9cbc2d9e..9c3c0e95 100644 --- a/src/render/appendChild.js +++ b/src/render/appendChild.js @@ -131,7 +131,6 @@ export function appendChild(svg, annotation, viewport) { child = renderPoint(annotation); break; case 'textbox': - console.log("check4"); child = renderText(annotation); break; case 'drawing': diff --git a/src/render/renderText.js b/src/render/renderText.js index 244d020e..f9913685 100644 --- a/src/render/renderText.js +++ b/src/render/renderText.js @@ -13,7 +13,7 @@ function insertLineBreaks(textElement, textContent) { // can't use dy attribute here since we want empty lines to take up space as well, // so we will update y manually based on font size const x = textElement.getAttribute('x'); - console.log("check2"); + console.log('check2'); let y = Number(textElement.getAttribute('y')); const size = Number(textElement.getAttribute('font-size')); for (const line of lines) { @@ -38,7 +38,7 @@ export default function renderText(a) { // Text should be rendered at 0 degrees relative to // document rotation let text = document.createElementNS('http://www.w3.org/2000/svg', 'text'); - console.log("check1") + console.log('check1'); setAttributes(text, { x: a.x, y: a.y, diff --git a/src/utils/setAttributes.js b/src/utils/setAttributes.js index 8f17ed42..adc8d94d 100644 --- a/src/utils/setAttributes.js +++ b/src/utils/setAttributes.js @@ -19,7 +19,6 @@ let keyCase = (key) => { * @param {Object} attributes The map of key/value pairs to use for attributes */ export default function setAttributes(node, attributes) { - console.log("check5") Object.keys(attributes).forEach((key) => { node.setAttribute(keyCase(key), attributes[key]); }); From a3488a63f28182557e469a0d386dd6c456391368 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Mon, 13 Jun 2022 16:43:16 -0400 Subject: [PATCH 04/10] test3 --- src/render/renderText.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/renderText.js b/src/render/renderText.js index f9913685..4739c390 100644 --- a/src/render/renderText.js +++ b/src/render/renderText.js @@ -13,8 +13,9 @@ function insertLineBreaks(textElement, textContent) { // can't use dy attribute here since we want empty lines to take up space as well, // so we will update y manually based on font size const x = textElement.getAttribute('x'); - console.log('check2'); + console.log(x); let y = Number(textElement.getAttribute('y')); + console.log(y); const size = Number(textElement.getAttribute('font-size')); for (const line of lines) { const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan'); @@ -38,7 +39,6 @@ export default function renderText(a) { // Text should be rendered at 0 degrees relative to // document rotation let text = document.createElementNS('http://www.w3.org/2000/svg', 'text'); - console.log('check1'); setAttributes(text, { x: a.x, y: a.y, From 1c0fbc9a266b052c16fa9f4a9b0ee23b0d2be603 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 02:10:35 -0400 Subject: [PATCH 05/10] test4 --- src/UI/text.js | 5 +++++ src/render/appendChild.js | 2 ++ src/render/renderText.js | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/UI/text.js b/src/UI/text.js index 34849195..7e17446c 100644 --- a/src/UI/text.js +++ b/src/UI/text.js @@ -91,6 +91,11 @@ function saveText() { rotation: -viewport.rotation }; + console.log('text' + pt[0]); + console.log('text' + pt[1]); + console.log('text' + clientX - rect.left); + console.log('text' + clientY - rect.top + height); + PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation) .then((annotation) => { appendChild(svg, annotation); diff --git a/src/render/appendChild.js b/src/render/appendChild.js index 9c3c0e95..9bcafb40 100644 --- a/src/render/appendChild.js +++ b/src/render/appendChild.js @@ -132,6 +132,8 @@ export function appendChild(svg, annotation, viewport) { break; case 'textbox': child = renderText(annotation); + console.log('AppendChild' + annotation.x); + console.log('AppendChild' + annotation.y); break; case 'drawing': child = renderPath(annotation); diff --git a/src/render/renderText.js b/src/render/renderText.js index 4739c390..150ce5d2 100644 --- a/src/render/renderText.js +++ b/src/render/renderText.js @@ -9,13 +9,13 @@ import normalizeColor from '../utils/normalizeColor'; * @param {String} textContent String to render with line breaks */ function insertLineBreaks(textElement, textContent) { + console.log(textContent); const lines = (textContent || '').split('\n'); // can't use dy attribute here since we want empty lines to take up space as well, // so we will update y manually based on font size const x = textElement.getAttribute('x'); - console.log(x); let y = Number(textElement.getAttribute('y')); - console.log(y); + // x y are NaN const size = Number(textElement.getAttribute('font-size')); for (const line of lines) { const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan'); @@ -39,6 +39,8 @@ export default function renderText(a) { // Text should be rendered at 0 degrees relative to // document rotation let text = document.createElementNS('http://www.w3.org/2000/svg', 'text'); + console.log('renderText' + a.x); + console.log(a.y); setAttributes(text, { x: a.x, y: a.y, From 5cb8020f6e95eaef8e0d353cd0c823b5356adc0a Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 02:56:13 -0400 Subject: [PATCH 06/10] test 6 --- src/UI/text.js | 6 ++++-- src/UI/utils.js | 2 ++ src/utils/mathUtils.js | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/UI/text.js b/src/UI/text.js index 7e17446c..1358af14 100644 --- a/src/UI/text.js +++ b/src/UI/text.js @@ -93,8 +93,10 @@ function saveText() { console.log('text' + pt[0]); console.log('text' + pt[1]); - console.log('text' + clientX - rect.left); - console.log('text' + clientY - rect.top + height); + console.log(clientX); + console.log(clientY); + console.log(rect.left); + console.log(height); PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation) .then((annotation) => { diff --git a/src/UI/utils.js b/src/UI/utils.js index bf742805..b69f424a 100644 --- a/src/UI/utils.js +++ b/src/UI/utils.js @@ -170,6 +170,8 @@ export function convertToSvgPoint(pt, svg, viewport) { let offset = getTranslation(viewport); xform = translate(xform, offset.x, offset.y); + console.log("utils", pt); + console.log("utils", xform); return applyInverseTransform(pt, xform); } diff --git a/src/utils/mathUtils.js b/src/utils/mathUtils.js index 3b1844d5..63fd1beb 100644 --- a/src/utils/mathUtils.js +++ b/src/utils/mathUtils.js @@ -11,6 +11,7 @@ export function applyTransform(p, m) { // export function applyInverseTransform(p, m) { let d = m[0] * m[3] - m[1] * m[2]; + console.log("mathutils", d); return [ (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d, (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d From 563e81eb3458ed4f862176df62af000f3b0dd9a9 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 03:24:25 -0400 Subject: [PATCH 07/10] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 245d2b08..d895e92a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@submitty/pdf-annotate.js", - "version": "2.4.0", + "version": "/usr/local/submitty/pdf-annotate.js", "description": "Annotation layer for pdf.js", "main": "index.js", "types": "types", From f6ea860a0193dd0e61edd9015c14a6736fd2a354 Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 03:30:40 -0400 Subject: [PATCH 08/10] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d895e92a..49bb30be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@submitty/pdf-annotate.js", - "version": "/usr/local/submitty/pdf-annotate.js", + "version": "2.4.0", "description": "Annotation layer for pdf.js", "main": "index.js", "types": "types", @@ -16,7 +16,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/Submitty/pdf-annotate.js.git" + "url": "git+https://github.com/Submitty/pdf-annotate.js.git#fix_text_position" }, "keywords": [ "pdf", From 080d86efc65b9e70ca89b39396e3060220300c5f Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 04:00:04 -0400 Subject: [PATCH 09/10] test6 --- src/UI/utils.js | 4 ++-- src/utils/mathUtils.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/UI/utils.js b/src/UI/utils.js index b69f424a..7ce3d17a 100644 --- a/src/UI/utils.js +++ b/src/UI/utils.js @@ -170,8 +170,8 @@ export function convertToSvgPoint(pt, svg, viewport) { let offset = getTranslation(viewport); xform = translate(xform, offset.x, offset.y); - console.log("utils", pt); - console.log("utils", xform); + console.log('utils', pt); + console.log('utils', xform); return applyInverseTransform(pt, xform); } diff --git a/src/utils/mathUtils.js b/src/utils/mathUtils.js index 63fd1beb..737c32b1 100644 --- a/src/utils/mathUtils.js +++ b/src/utils/mathUtils.js @@ -11,7 +11,7 @@ export function applyTransform(p, m) { // export function applyInverseTransform(p, m) { let d = m[0] * m[3] - m[1] * m[2]; - console.log("mathutils", d); + console.log('mathutils', d); return [ (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d, (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d From 99fc940dce73a3849d47ae46fe1133b14d26a36c Mon Sep 17 00:00:00 2001 From: Evan Shi <79226246+Eceptonsu@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:17:30 -0400 Subject: [PATCH 10/10] test7 --- package.json | 2 +- src/UI/text.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 49bb30be..245d2b08 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/Submitty/pdf-annotate.js.git#fix_text_position" + "url": "git+https://github.com/Submitty/pdf-annotate.js.git" }, "keywords": [ "pdf", diff --git a/src/UI/text.js b/src/UI/text.js index 1358af14..56d630d2 100644 --- a/src/UI/text.js +++ b/src/UI/text.js @@ -91,8 +91,8 @@ function saveText() { rotation: -viewport.rotation }; - console.log('text' + pt[0]); - console.log('text' + pt[1]); + console.log('text:' + pt[0]); + console.log('text:' + pt[1]); console.log(clientX); console.log(clientY); console.log(rect.left);