Skip to content

Commit e7ec771

Browse files
committed
New: Improved detection of image border when zoom is applied
1 parent f848463 commit e7ec771

File tree

2 files changed

+104
-17
lines changed

2 files changed

+104
-17
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1313
- Option to start OpenComic directly in last reading [`00cb8c7`](https://github.com/ollm/OpenComic/commit/00cb8c7da9eb8345aaec8faa3b5c91953c2350dd)
1414
- Recently opened page [`d2f3065`](https://github.com/ollm/OpenComic/commit/d2f30653f506993a45e49ad5e7e5e8434c33a9be)
1515
- Option to move zoom and scroll whit mouse [`e8cc79c`](https://github.com/ollm/OpenComic/commit/e8cc79cbddd23ff7d47b7046190cecbad199d3c2)
16-
- Improved touch screen navigation (swipe gesture, 2 finger zoom and reset zoom with 2 finger click)
16+
- Improved touch screen navigation (swipe gesture, 2 finger zoom and reset zoom with 2 finger click) [`f848463`](https://github.com/ollm/OpenComic/commit/f84846399f1521c736b9b6e048f204513ac304da)
17+
- Improved detection of image border when zoom is applied
1718

1819
##### 🐛 Bug Fixes
1920

scripts/reading.js

+102-16
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ function goToIndex(index, animation = true, nextPrevious = false, end = false)
930930

931931
if((readingViewIs('scroll') && (_config.readingViewAdjustToWidth || _config.readingWebtoon)) && pageVisibilityIndex !== false)
932932
{
933-
imgHeight = image.height() + _config.readingMargin.top;
933+
imgHeight = largerImage.height + _config.readingMargin.top;
934934

935935
if(imgHeight > contentHeight)
936936
{
@@ -1559,6 +1559,9 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
15591559
haveZoom = true;
15601560
}
15611561

1562+
let withLimits = notCrossZoomLimits(translateX, translateY, scale);
1563+
translateX = withLimits.x;
1564+
15621565
dom.this(contentRight).find('.reading-body > div, .reading-lens > div > div', true).css({
15631566
transition: 'transform '+animationDurationS+'s, z-index '+animationDurationS+'s',
15641567
transform: 'translateX('+app.roundDPR(translateX)+'px) translateY('+app.roundDPR(translateY)+'px) scale('+scale+')',
@@ -1601,6 +1604,8 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
16011604

16021605
fixBlurOnZoom(scale);
16031606

1607+
applyScaleST = false;
1608+
16041609
}, animationDurationS * 1000 + 100);
16051610
}
16061611
else
@@ -1645,6 +1650,11 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
16451650
haveZoom = true;
16461651
}
16471652

1653+
let withLimits = notCrossZoomLimits(translateX, translateY, scale);
1654+
1655+
translateX = withLimits.x;
1656+
translateY = withLimits.y;
1657+
16481658
dom.this(contentRight).find('.image-position'+currentZoomIndex, true).css({
16491659
transition: 'transform '+animationDurationS+'s, z-index '+animationDurationS+'s',
16501660
transform: 'translateX('+app.roundDPR(translateX)+'px) translateY('+app.roundDPR(translateY)+'px) scale('+scale+')',
@@ -1663,11 +1673,21 @@ function applyScale(animation = true, scale = 1, center = false, zoomOut = false
16631673

16641674
fixBlurOnZoom(scale, currentZoomIndex);
16651675

1676+
applyScaleST = false;
1677+
16661678
}, animationDurationS * 1000 + 100);
16671679
}
16681680

1669-
zoomMoveData.x = currentPageXY.x;
1670-
zoomMoveData.y = currentPageXY.y;
1681+
if(center)
1682+
{
1683+
zoomMoveData.x = (originalRect.left + originalRect.width / 2) - (translateX / scale);
1684+
zoomMoveData.y = (originalRect.top + originalRect.height / 2) - (translateY / scale);
1685+
}
1686+
else
1687+
{
1688+
zoomMoveData.x = currentPageXY.x;
1689+
zoomMoveData.y = currentPageXY.y;
1690+
}
16711691

16721692
scalePrevData = {
16731693
tranX: translateX,
@@ -1813,20 +1833,65 @@ function fixBlurOnZoom(scale = 1, index = false)
18131833

18141834
}
18151835

1816-
// Drag zoom
1817-
function dragZoom(x, y)
1836+
function getIndexImagesSize(index)
1837+
{
1838+
let contentRight = template._contentRight();
1839+
1840+
let width = 0;
1841+
let height = 0;
1842+
1843+
let images = contentRight.querySelectorAll('.reading-body .image-position'+index+' .r-img > *');
1844+
1845+
let len = images.length;
1846+
1847+
if(len == 1)
1848+
width += _config.readingMargin.left * 2;
1849+
1850+
for(let i = 0; i < len; i++)
1851+
{
1852+
let img = images[i];
1853+
1854+
width += +img.dataset.width;
1855+
1856+
if(i > 0)
1857+
{
1858+
if(i == 1)
1859+
width += +img.dataset.left * 3;
1860+
else
1861+
width += +img.dataset.left;
1862+
}
1863+
1864+
let _height = +img.dataset.height + (_config.readingMargin.top * 2);
1865+
1866+
if(_height > height) height = _height;
1867+
}
1868+
1869+
return {
1870+
width: width,
1871+
height: height,
1872+
};
1873+
}
1874+
1875+
function notCrossZoomLimits(x, y, scale = false)
18181876
{
1819-
x = scalePrevData.tranX2 + x;
1820-
y = scalePrevData.tranY2 + y;
1877+
scale = scale !== false ? scale : scalePrevData.scale;
1878+
1879+
let indexSize = getIndexImagesSize((config.readingGlobalZoom && readingViewIs('scroll')) ? (currentIndex - 1) : currentZoomIndex);
18211880

1822-
let maxX = originalRect.width * 0.5 * scalePrevData.scale - originalRect.width * 0.5;
1823-
let minX = originalRect.width * -0.5 * scalePrevData.scale - originalRect.width * -0.5;
1881+
let maxX = indexSize.width * 0.5 * scale - originalRect.width * 0.5;
1882+
let minX = indexSize.width * -0.5 * scale - originalRect.width * -0.5;
1883+
1884+
if(maxX < 0) maxX = 0;
1885+
if(minX > 0) minX = 0;
18241886

18251887
let maxDiff = readingViewIs('scroll') ? ((originalRect.top + originalRect.height) - (originalRectReadingBody.top + originalRectReadingBody.height)) : 0;
18261888
let minDiff = readingViewIs('scroll') ? (originalRect.top - originalRectReadingBody.top) : 0;
18271889

1828-
let maxY = (originalRect.height * 0.5 * scalePrevData.scale - originalRect.height * 0.5) - (minDiff < 0 ? minDiff : 0);
1829-
let minY = (originalRect.height * -0.5 * scalePrevData.scale - originalRect.height * -0.5) - (maxDiff > 0 ? maxDiff + _config.readingMargin.top : 0);
1890+
let maxY = (indexSize.height * 0.5 * scale - originalRect.height * 0.5) - (minDiff < 0 ? minDiff : 0);
1891+
let minY = (indexSize.height * -0.5 * scale - originalRect.height * -0.5) - (maxDiff > 0 ? maxDiff + _config.readingMargin.top : 0);
1892+
1893+
if(maxY < 0) maxY = 0;
1894+
if(minY > 0) minY = 0;
18301895

18311896
if(x > maxX)
18321897
x = maxX;
@@ -1838,6 +1903,17 @@ function dragZoom(x, y)
18381903
else if(y < minY)
18391904
y = minY;
18401905

1906+
return {x: x, y: y, maxX: maxX, maxY: maxY};
1907+
}
1908+
1909+
// Drag zoom
1910+
function dragZoom(x, y)
1911+
{
1912+
let withLimits = notCrossZoomLimits(scalePrevData.tranX2 + x, scalePrevData.tranY2 + y);
1913+
1914+
x = withLimits.x;
1915+
y = withLimits.y;
1916+
18411917
let contentRight = template._contentRight();
18421918

18431919
if(config.readingGlobalZoom && readingViewIs('scroll'))
@@ -2102,6 +2178,14 @@ function magnifyingGlassControl(mode, e = false, lensData = false)
21022178

21032179
function resizedWindow()
21042180
{
2181+
originalRect = false;
2182+
originalRectReadingBody = false;
2183+
originalRect2 = false;
2184+
originalRectReadingBody2 = false;
2185+
contentLeftRect = false;
2186+
contentRightRect = false;
2187+
barHeaderRect = false;
2188+
21052189
if(onReading || _onReading)
21062190
{
21072191
disposeImages();
@@ -3175,13 +3259,15 @@ function mousemove(event)
31753259
{
31763260
event.preventDefault();
31773261

3178-
let _pageX = pageX - contentRightRect.left;
3179-
let _pageY = pageY - contentRightRect.top;
3262+
let withLimits = notCrossZoomLimits(0, 0);
3263+
3264+
let widthM = contentRightRect.width / 2;
3265+
let heightM = contentRightRect.height / 2;
31803266

3181-
let x = -(_pageX - contentRightRect.width / 2) * (scalePrevData.scale - 1);
3182-
let y = -(_pageY - contentRightRect.height / 2) * (scalePrevData.scale - 1);
3267+
let x = -(pageX - zoomMoveData.x) * (withLimits.maxX / widthM * 1.2);
3268+
let y = -(pageY - zoomMoveData.y) * (withLimits.maxY / heightM * 1.2);
31833269

3184-
dragZoom(x - scalePrevData.tranX2, y - scalePrevData.tranY2);
3270+
dragZoom(x, y);
31853271

31863272
scalePrevData.tranX = zoomMoveData.tranX;
31873273
scalePrevData.tranY = zoomMoveData.tranY;

0 commit comments

Comments
 (0)