Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show baselines #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/org/primaresearch/page/viewer/PageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ else if (pageFilePath == null)
}

//Resolve
if (imageFilePath != null && resolveDir != null)
if (imageFilePath != null && resolveDir != null && ! new File(imageFilePath).isAbsolute())
imageFilePath = resolveDir + (resolveDir.endsWith(File.separator) ? "" : File.separator) + imageFilePath;

Display display = new Display();
Expand Down
21 changes: 21 additions & 0 deletions src/org/primaresearch/page/viewer/ui/render/DrawingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ public static void drawPolygon(GC gc, Color color, Polygon coords) {
gc.drawPolygon(polygon);
}

/**
* Draws the given line string
*/
public static void drawMultiline(GC gc, Color color, Polygon coords) {
int polyline[] = new int[coords.getSize()*2];

for (int i=0; i<coords.getSize(); i++) {
Point p = coords.getPoint(i);
polyline[i*2] = p.x;
polyline[i*2+1] = p.y;
}

gc.setForeground(color);
gc.setBackground(color);
gc.setAlpha(150);
int w = gc.getLineWidth();
gc.setLineWidth(w * 2);
gc.drawPolyline(polyline);
gc.setLineWidth(w);
}

/**
* Draws a line with arrow end
*/
Expand Down
19 changes: 13 additions & 6 deletions src/org/primaresearch/page/viewer/ui/views/DocumentImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.primaresearch.dla.page.layout.physical.Region;
import org.primaresearch.dla.page.layout.physical.shared.LowLevelTextType;
import org.primaresearch.dla.page.layout.physical.shared.RegionType;
import org.primaresearch.dla.page.layout.physical.text.impl.TextLine;
import org.primaresearch.maths.geometry.Point;
import org.primaresearch.maths.geometry.Polygon;
import org.primaresearch.page.viewer.Document;
Expand Down Expand Up @@ -101,9 +102,9 @@ private void init() {
imageCanvas.addMouseTrackListener(this);
imageCanvas.addMouseMoveListener(this);

parent.addMouseWheelListener(imageCanvas);
//parent.addMouseMoveListener(imageCanvas);
parent.addMouseWheelListener(this);
imageCanvas.addMouseWheelListener(imageCanvas);
//imageCanvas.addMouseMoveListener(imageCanvas);
imageCanvas.addMouseWheelListener(this);

tooltip = new PageElementTooltip(viewPane.getShell());
tooltip.activateHoverHelp(imageCanvas);
Expand Down Expand Up @@ -302,6 +303,11 @@ private void drawTextlines(GC gc) {
gc.setLineWidth(1);
for (ContentIterator it = docLayout.iterator(LowLevelTextType.TextLine); it.hasNext(); ) {
ContentObject region = it.next();
if (region instanceof TextLine &&
((TextLine)region).getBaseline() != null) {
Polygon baseline = ((TextLine)region).getBaseline();
DrawingHelper.drawMultiline(gc, getContentObjectColor(region), baseline);
}
if (region.getCoords() != null) {
Polygon coords = region.getCoords();
DrawingHelper.drawPolygon(gc, getContentObjectColor(region), coords);
Expand Down Expand Up @@ -554,7 +560,7 @@ Point getReadingOrderStartPoint(GroupMember element) {

//RegionRef
if (element instanceof RegionRef) {
Region region = docLayout.getRegion(((RegionRef)element).getRegionId(), true);
Region region = (Region)docLayout.getRegion(((RegionRef)element).getRegionId());
if (region != null) {
return region.getCoords().getBoundingBox().getCenter();
}
Expand Down Expand Up @@ -608,7 +614,7 @@ Point getReadingOrderEndPoint(GroupMember element) {

//RegionRef (centre = centre of bounding box)
if (element instanceof RegionRef) {
Region region = (Region)docLayout.getRegion(((RegionRef)element).getRegionId(), true);
Region region = (Region)docLayout.getRegion(((RegionRef)element).getRegionId());
if (region != null)
ret = region.getCoords().getBoundingBox().getCenter();
}
Expand Down Expand Up @@ -742,7 +748,8 @@ public void mouseMove(MouseEvent e) {

@Override
public void mouseScrolled(MouseEvent e) {
if ((e.stateMask & SWT.MOD1) != 0) { //CTRL
// non-CTRL already handled by SWTImageCanvas
if ((e.stateMask & (SWT.CTRL | SWT.COMMAND)) != 0) {
if (e.count > 0)
zoomIn();
else
Expand Down
15 changes: 11 additions & 4 deletions src/uky/article/imageviewer/views/SWTImageCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,17 @@ public AffineTransform getTransform() {

@Override
public void mouseScrolled(MouseEvent e) {
if ((e.stateMask & SWT.MOD1) == 0) { //No CTRL
ScrollBar scrollBar = getVerticalBar();
scrollBar.setSelection(scrollBar.getSelection()-e.count*10);
scrollVertically(scrollBar);
// CTRL already handled by DocumentImageView
if ((e.stateMask & (SWT.CTRL | SWT.COMMAND)) == 0) {
if ((e.stateMask & (SWT.SHIFT | SWT.ALT)) != 0) {
ScrollBar scrollBar = getHorizontalBar();
scrollBar.setSelection(scrollBar.getSelection()-e.count*10);
scrollHorizontally(scrollBar);
} else {
ScrollBar scrollBar = getVerticalBar();
scrollBar.setSelection(scrollBar.getSelection()-e.count*10);
scrollVertically(scrollBar);
}
}
}

Expand Down