Skip to content

Commit 0556b6d

Browse files
committed
feat: add fitHeight and alignment params for zone display
Add fitHeight parameter to showRect methods in ImageViewer and OpenSeaDragonViewer to force zone height to fill container while left-aligning content. This ensures each part shows its full staff at common zoom in measure-based view. Add alignment parameter to OpenSeaDragonViewer.showRect to support positioning zones horizontally ('left', 'right', 'center') for proper display in spread layouts. Update MeasureBasedView to pass fitHeight=true and alignment based on part position in row for correct multi-part rendering.
1 parent dd68c2b commit 0556b6d

3 files changed

Lines changed: 67 additions & 16 deletions

File tree

app/view/window/image/ImageViewer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ Ext.define('EdiromOnline.view.window.image.ImageViewer', {
672672
me.showRect(0, 0, me.imgWidth, me.imgHeight);
673673
},
674674

675-
showRect: function(x, y, width, height, highlight) {
675+
showRect: function(x, y, width, height, highlight, fitHeight) {
676676

677677
var me = this;
678678

@@ -684,7 +684,8 @@ Ext.define('EdiromOnline.view.window.image.ImageViewer', {
684684
y:y,
685685
width:width,
686686
height:height,
687-
highlight:highlight
687+
highlight:highlight,
688+
fitHeight:fitHeight
688689
};
689690

690691
me.hiResImg.hide();
@@ -698,7 +699,13 @@ Ext.define('EdiromOnline.view.window.image.ImageViewer', {
698699
var diffWidth = 0;
699700
var diffHeight = 0;
700701

701-
if((contWidth / width) > (contHeight / height)) {
702+
// fitHeight forces the zone height to fill the container and left-aligns it (no centering),
703+
// so each part shows its full staff at the common zoom and the measures start at the same x
704+
// across the vertically stacked parts in measureBasedView. Otherwise fit to whichever
705+
// dimension is more constraining and centre (default, used by the page-based view).
706+
if(fitHeight) {
707+
me.setSVGZoom((contHeight / height));
708+
}else if((contWidth / width) > (contHeight / height)) {
702709
me.setSVGZoom((contHeight / height));
703710
diffWidth = Math.round((contWidth - (width * me.zoom)) / 2);
704711
}else {
@@ -726,7 +733,7 @@ Ext.define('EdiromOnline.view.window.image.ImageViewer', {
726733
// Re-fit the stored rect to the (now final) container size so the zone keeps the same
727734
// displayed height across viewers; fall back to a hi-res refresh when nothing is shown.
728735
if(me.rect && me.rect != null)
729-
me.showRect(me.rect.x, me.rect.y, me.rect.width, me.rect.height, false);
736+
me.showRect(me.rect.x, me.rect.y, me.rect.width, me.rect.height, false, me.rect.fitHeight);
730737
else
731738
me.calculateHiResImg();
732739
},

app/view/window/image/OpenSeaDragonViewer.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Ext.define('EdiromOnline.view.window.image.OpenSeaDragonViewer', {
126126
}]
127127
});
128128
me.viewer.addOnceHandler('tile-drawn', function() {
129-
if(me.rect && me.rect != null) me.showRect(me.rect.x, me.rect.y, me.rect.width, me.rect.height, me.rect.highlight);
129+
if(me.rect && me.rect != null) me.showRect(me.rect.x, me.rect.y, me.rect.width, me.rect.height, me.rect.highlight, me.rect.fitHeight);
130130
});
131131
me.fireEvent('imageChanged', me, path, pageId);
132132
},
@@ -162,15 +162,17 @@ Ext.define('EdiromOnline.view.window.image.OpenSeaDragonViewer', {
162162
};
163163
},
164164

165-
showRect: function(x, y, width, height, highlight) {
165+
showRect: function(x, y, width, height, highlight, fitHeight, alignment) {
166166

167167
var me = this;
168168
me.rect = {
169-
x:x,
170-
y:y,
171-
width:width,
172-
height:height,
173-
highlight:highlight
169+
x: x,
170+
y: y,
171+
width: width,
172+
height: height,
173+
highlight: highlight,
174+
fitHeight: fitHeight,
175+
alignment: alignment || 'center'
174176
};
175177

176178
me.fitStoredRect();
@@ -181,7 +183,33 @@ Ext.define('EdiromOnline.view.window.image.OpenSeaDragonViewer', {
181183
var me = this;
182184
if(!me.viewer || !me.rect || me.rect == null) return;
183185

184-
var rect = me.viewer.viewport.imageToViewportRectangle(me.rect.x, me.rect.y, me.rect.width, me.rect.height);
186+
var r = me.rect;
187+
188+
// fitHeight maps the zone height to the full container height and positions the visible
189+
// region horizontally according to r.alignment:
190+
// 'left' – zone's left edge at the left of the viewport (right-side page in a spread)
191+
// 'right' – zone's right edge at the right of the viewport (left-side page in a spread)
192+
// 'center' – zone centred in the viewport (single viewer or inner part)
193+
if(r.fitHeight) {
194+
var contW = me.getWidth();
195+
var contH = me.getHeight();
196+
if(contW > 0 && contH > 0) {
197+
var visWidth = r.height * (contW / contH);
198+
var xStart;
199+
if(r.alignment === 'left') {
200+
xStart = r.x;
201+
} else if(r.alignment === 'right') {
202+
xStart = r.x + r.width - visWidth;
203+
} else {
204+
xStart = r.x + r.width / 2 - visWidth / 2;
205+
}
206+
var hRect = me.viewer.viewport.imageToViewportRectangle(xStart, r.y, visWidth, r.height);
207+
me.viewer.viewport.fitBounds(hRect, true);
208+
return;
209+
}
210+
}
211+
212+
var rect = me.viewer.viewport.imageToViewportRectangle(r.x, r.y, r.width, r.height);
185213
me.viewer.viewport.fitBoundsWithConstraints(rect);
186214
},
187215

app/view/window/source/MeasureBasedView.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,28 @@ Ext.define('EdiromOnline.view.window.source.HorizontalMeasureViewer', {
651651
// remember the tallest slice as this part's representative height
652652
if(height > partHeight) partHeight = height;
653653

654-
viewer.showRect(ulx, uly, width, height, true);
654+
// fitHeight=true so each part shows its full staff height at the common zoom.
655+
// Alignment depends on position in the row:
656+
// single viewer → center
657+
// two viewers → right (left viewer) / left (right viewer)
658+
// three or more → right (first) / left (last) / center (inner)
659+
var alignment;
660+
if(viewerCount <= 1) {
661+
alignment = 'center';
662+
} else if(i === 0) {
663+
alignment = 'right';
664+
} else if(i === viewerCount - 1) {
665+
alignment = 'left';
666+
} else {
667+
alignment = 'center';
668+
}
669+
viewer.showRect(ulx, uly, width, height, true, true, alignment);
655670
}
656671

657-
// Split the vertical space between parts proportionally to each part's zone height
658-
// instead of equally (the previous flex:1 gave every part height/number-of-parts).
659-
// The image viewers re-fit to the new row height via their onResize handler.
672+
// Split the vertical space between parts proportionally to each part's height. Because each
673+
// part is fit to its row height, rowHeight ∝ height makes the resulting zoom identical for
674+
// every part (the common zoom ≈ windowHeight / Σ partHeight), and every staff is shown in
675+
// full. The image viewers re-fit to the new row height via their onResize handler.
660676
if(partHeight > 0) {
661677
me.flex = partHeight;
662678
if(me.ownerCt) me.ownerCt.updateLayout();

0 commit comments

Comments
 (0)