Permalink
Browse files

Added some damn boxes already

  • Loading branch information...
1 parent 8a73ba0 commit f9676a6549938cb3015239844e99df5bb74debba Michal Migurski committed Mar 21, 2012
Showing with 63 additions and 6 deletions.
  1. +47 −3 decoder/compose2.py
  2. +16 −3 site/lib/lib.compose.php
View
@@ -250,7 +250,7 @@ def add_scale_bar(ctx, mmap, map_height_pt):
ctx.restore()
-def add_print_page(ctx, mmap, href, well_bounds_pt, points_FG, hm2pt_ratio, layout, text, mark, fuzzy):
+def add_print_page(ctx, mmap, href, well_bounds_pt, points_FG, hm2pt_ratio, layout, text, mark, fuzzy, indexees):
"""
"""
print 'Adding print page:', href
@@ -285,7 +285,6 @@ def add_print_page(ctx, mmap, href, well_bounds_pt, points_FG, hm2pt_ratio, layo
#
# Draw a dot if need be
#
-
if fuzzy is not None:
loc = Location(fuzzy[1], fuzzy[0])
pt = mmap.locationPoint(loc)
@@ -318,6 +317,30 @@ def add_print_page(ctx, mmap, href, well_bounds_pt, points_FG, hm2pt_ratio, layo
ctx.fill()
#
+ # Perhaps some boxes?
+ #
+ page_numbers = []
+
+ for page in indexees:
+ north, west, south, east = page['bounds']
+
+ ul = mmap.locationPoint(Location(north, west))
+ lr = mmap.locationPoint(Location(south, east))
+
+ x1 = map_width_pt * float(ul.x) / mmap.dimensions.x
+ x2 = map_width_pt * float(lr.x) / mmap.dimensions.x
+ y1 = map_height_pt * float(ul.y) / mmap.dimensions.y
+ y2 = map_height_pt * float(lr.y) / mmap.dimensions.y
+
+ draw_box(ctx, x1, y1, x2-x1, y2-y1)
+ ctx.set_source_rgb(0, 0, 0)
+ ctx.set_line_width(1)
+ ctx.set_dash([])
+ ctx.stroke()
+
+ page_numbers.append((x1, y1, x2, y2, page['number']))
+
+ #
# Calculate positions of registration points
#
ctx.save()
@@ -400,6 +423,21 @@ def add_print_page(ctx, mmap, href, well_bounds_pt, points_FG, hm2pt_ratio, layo
ctx.show_text(line)
add_scale_bar(ctx, mmap, map_height_pt)
+
+ ctx.set_font_face(font)
+ ctx.set_font_size(18)
+
+ for (x1, y1, x2, y2, number) in page_numbers:
+ number_w, number_h = ctx.text_extents(number)[2:4]
+ offset_x, offset_y = (x1 + x2 - number_w) / 2, (y1 + y2 + number_h) / 2
+
+ draw_box(ctx, offset_x - 4, offset_y - number_h - 4, number_w + 8, number_h + 8)
+ ctx.set_source_rgb(1, 1, 1)
+ ctx.fill()
+
+ ctx.set_source_rgb(0, 0, 0)
+ ctx.move_to(offset_x, offset_y)
+ ctx.show_text(number)
ctx.show_page()
@@ -484,6 +522,7 @@ def main(apibase, password, print_id, pages, paper_size, orientation, layout):
mark = page.get('mark', None) or None
fuzzy = page.get('fuzzy', None) or None
text = str(page.get('text', None) or '')
+ role = page.get('role', None) or None
north, west, south, east = page['bounds']
northwest = Location(north, west)
@@ -493,7 +532,12 @@ def main(apibase, password, print_id, pages, paper_size, orientation, layout):
yield 60
- add_print_page(print_context, page_mmap, page_href, map_bounds_pt, points_FG, hm2pt_ratio, layout, text, mark, fuzzy)
+ if role == 'index':
+ indexees = [pages[other] for other in range(len(pages)) if other != index]
+ else:
+ indexees = []
+
+ add_print_page(print_context, page_mmap, page_href, map_bounds_pt, points_FG, hm2pt_ratio, layout, text, mark, fuzzy, indexees)
#
# Now make a smaller preview map for the page,
View
@@ -176,12 +176,24 @@ function adjust_mmap_dimensions($aspect_ratio, $mmap)
/**
* Return north, west, south, east array for an mmap instance.
+ *
+ * Optionally inflate the bounds by some factor.
*/
- function get_mmap_bounds($mmap)
+ function get_mmap_bounds($mmap, $inflate=0)
{
$northwest = $mmap->pointLocation(new MMaps_Point(0, 0));
$southeast = $mmap->pointLocation($mmap->dimensions);
- $bounds = array($northwest->lat, $northwest->lon, $southeast->lat, $southeast->lon);
+
+ $lat_span = $northwest->lat - $southeast->lat;
+ $lon_span = $southeast->lon - $northwest->lon;
+
+ $lat_buff = $lat_span * $inflate;
+ $lon_buff = $lon_span * $inflate;
+
+ $bounds = array($northwest->lat + $lat_buff,
+ $northwest->lon - $lon_buff,
+ $southeast->lat - $lat_buff,
+ $southeast->lon + $lon_buff);
return $bounds;
}
@@ -263,8 +275,9 @@ function compose_from_postvars(&$dbh, $post, $user_id)
$index = array('number' => 'i',
'zoom' => $mmap->coordinate->zoom,
- 'bounds' => get_mmap_bounds($mmap),
+ 'bounds' => get_mmap_bounds($mmap, 0.1),
'provider' => $provider,
+ 'role' => 'index',
'text' => ''
);

0 comments on commit f9676a6

Please sign in to comment.