Skip to content

Commit d757121

Browse files
committed
fix pdf line break
1 parent f9e02d7 commit d757121

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

doc/description.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Mouseover Translate Any Language At Once
1919
English, Russian, Japanese, Chinese and so on
2020

2121
# Change Log
22+
- 0.1.206
23+
- fix pdf line break (requested by mrk67422)
2224
- 0.1.205
2325
- Add right mouse hold in pdf viewer now act as handtool (contributed by Witnull)
2426
- filter parenthesis text from tts (requested by Gobidobi)

src/event/mouseover.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export async function getMouseoverText(x, y) {
108108
var mouseoverText = getTextFromRange(range, mouseoverType);
109109
// if fail detect using expand range use seg range
110110
if (
111-
!isFirefox() &&
111+
!shouldUseSegmentation() &&
112112
(mouseoverType === "word" || mouseoverType === "sentence") &&
113113
!mouseoverText["mouseoverText"] &&
114114
checkContainerDetectText(range) // check if container detect text
@@ -130,6 +130,10 @@ function getTextFromRange(range, mouseoverType, useSegmentation= false) {
130130
return output;
131131
}
132132

133+
function shouldUseSegmentation() {
134+
return isFirefox() || util.isPDFViewer();
135+
}
136+
133137
function expandRange(range, type, useSegmentation) {
134138
try {
135139
if (!range) {
@@ -138,7 +142,7 @@ function expandRange(range, type, useSegmentation) {
138142
if (type == "container") {
139143
// get whole text paragraph
140144
range = getContainerRange(range);
141-
} else if (isFirefox() || useSegmentation) {
145+
} else if (shouldUseSegmentation() || useSegmentation) {
142146
// for firefox, use segmentation to extract word
143147
range = expandRangeWithSeg(range, type);
144148
} else {

src/pdf/pdfInject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ function waitUntilPdfLoad() {
8888
async function addSpaceBetweenPdfText() {
8989
var prevY;
9090
var prevLine;
91-
var newLineScale = 1.5;
92-
var spaceScale = 1.0;
91+
var newLineScale = 1.3; // if line gap more than 1.3 times font size, add new line
92+
var spaceScale = 1.0; // if line gap more than 1.0 times font size, add space
9393

9494
// remove all br
9595
$("br").remove();

0 commit comments

Comments
 (0)