[cairo-commit] roadster/src import.c, 1.4, 1.5 import_tiger.c, 1.5,
1.6 layers.c, 1.3, 1.4 map.c, 1.5, 1.6 searchwindow.c, 1.3, 1.4
Ian McIntosh
commit at pdx.freedesktop.org
Tue Feb 22 09:33:16 PST 2005
Committed by: ian
Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv1064/src
Modified Files:
import.c import_tiger.c layers.c map.c searchwindow.c
Log Message:
* import_tiger.c: Added extracting of polygon labels.
* map.c: Added polygon label drawing.
Index: import.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- import.c 22 Feb 2005 17:12:27 -0000 1.4
+++ import.c 22 Feb 2005 17:33:14 -0000 1.5
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
+
#include "../include/import.h"
#include "../include/importwindow.h"
#include "../include/import_tiger.h"
Index: import_tiger.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import_tiger.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- import_tiger.c 22 Feb 2005 17:12:27 -0000 1.5
+++ import_tiger.c 22 Feb 2005 17:33:14 -0000 1.6
@@ -896,6 +896,11 @@
db_insert_road(pRecordRT7->m_nRecordType,
0,0,0,0,
pTempPointsArray, &nRoadID);
+
+ if(pRecordRT7->m_achName[0] != '\0') {
+ printf("inserting area name %s\n", pRecordRT7->m_achName);
+ db_insert_roadname(nRoadID, pRecordRT7->m_achName, 0);
+ }
}
}
g_ptr_array_free(pTempPointsArray, FALSE);
Index: layers.c
===================================================================
RCS file: /cvs/cairo/roadster/src/layers.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- layers.c 22 Feb 2005 04:47:24 -0000 1.3
+++ layers.c 22 Feb 2005 17:33:14 -0000 1.4
@@ -61,8 +61,8 @@
/* 2 */ {LAYER_MAJORSTREET, "Major Roads",
{{
- {{0.0, 0.0, 2.0, 3.0, 5.0, 10.0, 14.0, 17.0, 24.0,32.0}, {173/255.0, 162/255.0, 140/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT},
- {{0.0, 0.0, 1.8, 2.5, 4.3, 9.0, 13.0, 15.5, 22.0,30.0}, {255/255.0, 251/255.0, 115/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
+ {{0.0, 0.0, 2.0, 3.0, 5.0, 10.0, 14.0, 17.0, 24.0,32.0}, {173/255.0, 162/255.0, 140/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND},
+ {{0.0, 0.0, 1.8, 2.5, 4.3, 9.0, 13.0, 15.5, 22.0,30.0}, {255/255.0, 251/255.0, 115/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND}
}},
{{0,0,0,0,0,6,8,10,16,26}, /* font size */
@@ -73,8 +73,8 @@
/* 3 */ {LAYER_MINORHIGHWAY, "Minor Highways",
{{
- {{0.0, 0.0, 4.0, 5.0, 8.0, 9.0, 17.0,22.0,28.0,36.0}, {173/255.0, 162/255.0, 140/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT},
- {{0.0, 0.0, 3.5, 4.1, 6.8, 7.5, 15.0,20.0,26.0,34.0}, {255/255.0, 202/255.0, 58/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
+ {{0.0, 0.0, 4.0, 5.0, 8.0, 9.0, 17.0,22.0,28.0,36.0}, {173/255.0, 162/255.0, 140/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND},
+ {{0.0, 0.0, 3.5, 4.1, 6.8, 7.5, 15.0,20.0,26.0,34.0}, {255/255.0, 202/255.0, 58/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND}
}},
{{0,0,0,0,0,0,8,8,10,18}, /* font size */
@@ -85,8 +85,8 @@
/* 4 */ {LAYER_MINORHIGHWAY_RAMP, "Minor Highway Ramps",
{{
- {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 5.0,8.0,10.0}, {173/255.0, 142/255.0, 33/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT},
- {{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.5, 3.5,6.0,8.0}, {247/255.0, 223/255.0, 74/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
+ {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 5.0,8.0,10.0}, {173/255.0, 142/255.0, 33/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND},
+ {{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.5, 3.5,6.0,8.0}, {247/255.0, 223/255.0, 74/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_ROUND}
}},
{{0,0,0,0,0,0,8,8,10,18}, /* font size */
@@ -137,22 +137,22 @@
{{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {135/255.0, 172/255.0, 126/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
}},
- {{0,0,0,0,0,0,0,6,8,10}, /* font size */
- {0,0,0,0,0,0,0,0,0,0}, /* bold */
- {0,0,0,0,0,0,0,0,0,0}, /* halo */
- {0,0,0,0}},
+ {{0,0,0,0,0,0,12,14,14,16}, /* font size */
+ {0,0,0,0,0,0,1,1,1,1}, /* bold */
+ {0,0,0,0,0,0,1,1,1,1}, /* halo */
+ {0.25,0.5,0.25, 1.0}},
NULL},
/* 9 */{LAYER_RIVER, "Rivers",
{{
- {{0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 6.0, 10.0, 14.0, 18.0}, {148/255.0, 178/255.0, 197/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT},
- {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0/255.0, 0/255.0, 0/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
+ {{0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 6.0, 10.0, 14.0, 18.0}, {148/255.0, 178/255.0, 197/255.0, 1.00}, 0, CAIRO_LINE_JOIN_ROUND, CAIRO_LINE_CAP_ROUND},
+ {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0/255.0, 0/255.0, 0/255.0, 1.00}, 0, CAIRO_LINE_JOIN_ROUND, CAIRO_LINE_CAP_ROUND}
}},
- {{0,0,0,0,0,0,0,6,8,10}, /* font size */
- {0,0,0,0,0,0,0,0,0,0}, /* bold */
- {0,0,0,0,0,0,0,0,0,0}, /* halo */
- {0,0,0,0}},
+ {{0,0,0,0,0,0,12,14,14,16}, /* font size */
+ {0,0,0,0,0,0,1,1,1,1}, /* bold */
+ {0,0,0,0,0,0,1,1,1,1}, /* halo */
+ {128/255.0, 158/255.0, 180/255.0, 1.0}},
NULL},
/* 10 */{LAYER_LAKE, "Lakes",
@@ -161,10 +161,10 @@
{{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0/255.0, 0/255.0, 0/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
}},
- {{0,0,0,0,0,0,0,6,8,10}, /* font size */
- {0,0,0,0,0,0,0,0,0,0}, /* bold */
- {0,0,0,0,0,0,0,0,0,0}, /* halo */
- {0,0,0,0}},
+ {{0,0,0,0,0,0,12,14,14,16}, /* font size */
+ {0,0,0,0,0,0,1,1,1,1}, /* bold */
+ {0,0,0,0,0,0,1,1,1,1}, /* halo */
+ {128/255.0, 158/255.0, 180/255.0, 1.0}},
NULL},
/* 11 */{LAYER_MISC_AREA, "Misc Areas",
@@ -173,10 +173,10 @@
{{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0/255.0, 0/255.0, 0/255.0, 1.00}, 0, CAIRO_LINE_JOIN_MITER, CAIRO_LINE_CAP_BUTT}
}},
- {{0,0,0,0,0,0,0,0,0,0}, /* font size */
- {0,0,0,0,0,0,0,0,0,0}, /* bold */
- {0,0,0,0,0,0,0,0,0,0}, /* halo */
- {0,0,0,0}},
+ {{0,0,0,0,0,0,12,16,16,18}, /* font size */
+ {0,0,0,0,0,0,1,1,1,1}, /* bold */
+ {0,0,0,0,0,0,1,1,1,1}, /* halo */
+ {0.25,0.25,0.25,1.0}},
NULL},
};
Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- map.c 22 Feb 2005 17:12:27 -0000 1.5
+++ map.c 22 Feb 2005 17:33:14 -0000 1.6
@@ -171,13 +171,6 @@
#define LABEL_PIXELS_ABOVE_LINE (2)
#define LABEL_PIXEL_RELIEF_INSIDE_LINE (2) // when drawing a label inside a line, only do so if we would have at least this much blank space above+below the text
-/* Prototypes */
-
-void map_draw_layer_polygons(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
-void map_draw_layer_lines(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
-void map_draw_layer_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
-
-void map_draw_layer_points(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pLocationsArray);
//void map_draw_layer_railroad(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, sublayerstyle_t* pSubLayerStyle);
// For road names: Bitstream Vera Sans Mono ?
@@ -212,6 +205,18 @@
#define DEG2RAD(x) ((x) * (M_PI / 180.0))
#define RAD2DEG(x) ((x) * (180.0 / M_PI))
+
+/* Prototypes */
+
+void map_draw_layer_polygons(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
+void map_draw_layer_lines(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
+void map_draw_layer_line_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
+void map_draw_layer_polygon_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
+
+void map_draw_polygon_label(cairo_t *pCairo, textlabelstyle_t* pLabelStyle, rendermetrics_t* pRenderMetrics, pointstring_t* pPointString, const gchar* pszLabel);
+void map_draw_layer_points(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pLocationsArray);
+
+
// Each zoomlevel has a scale and an optional name (name isn't used for anything)
zoomlevel_t g_sZoomLevels[NUM_ZOOMLEVELS+1] = {
{1,"undefined"}, // no zoom level 0
@@ -250,7 +255,6 @@
{LAYER_MINORHIGHWAY_RAMP, 1, map_draw_layer_lines},
{LAYER_MINORSTREET, 1, map_draw_layer_lines},
-
{LAYER_MAJORSTREET, 1, map_draw_layer_lines},
{LAYER_RAILROAD, 0, map_draw_layer_lines},
@@ -259,11 +263,16 @@
{LAYER_MINORHIGHWAY, 0, map_draw_layer_lines},
{LAYER_MINORHIGHWAY, 1, map_draw_layer_lines},
- {LAYER_MINORSTREET, 0, map_draw_layer_labels},
- {LAYER_MAJORSTREET, 0, map_draw_layer_labels},
- {LAYER_RAILROAD, 0, map_draw_layer_labels},
- {LAYER_MINORHIGHWAY, 0, map_draw_layer_labels},
-/// {LAYER_MAJORHIGHWAY, 0, map_draw_layer_labels},
+ // LABELS
+ {LAYER_MINORSTREET, 0, map_draw_layer_line_labels},
+ {LAYER_MAJORSTREET, 0, map_draw_layer_line_labels},
+ {LAYER_RAILROAD, 0, map_draw_layer_line_labels},
+ {LAYER_MINORHIGHWAY, 0, map_draw_layer_line_labels},
+/// {LAYER_MAJORHIGHWAY, 0, map_draw_layer_line_labels},
+
+ {LAYER_MISC_AREA, 0, map_draw_layer_polygon_labels},
+ {LAYER_PARK, 0, map_draw_layer_polygon_labels},
+ {LAYER_LAKE, 0, map_draw_layer_polygon_labels},
};
// ========================================================
@@ -685,7 +694,7 @@
cairo_set_alpha(pCairo, 1.0);
cairo_rotate(pCairo, fAngleInRadians);
cairo_text_path(pCairo, azLabelSegment);
-
+
gboolean bDrawHalo = pLabelStyle->m_abHaloAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
if(bDrawHalo) {
cairo_save(pCairo);
@@ -700,6 +709,91 @@
cairo_restore(pCairo);
}
+void map_draw_polygon_label(cairo_t *pCairo, textlabelstyle_t* pLabelStyle, rendermetrics_t* pRenderMetrics, pointstring_t* pPointString, const gchar* pszLabel)
+{
+ if(pPointString->m_pPointsArray->len < 3) return;
+
+ gdouble fFontSize = pLabelStyle->m_afFontSizeAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
+ if(fFontSize == 0) return;
+
+ gdouble fAlpha = pLabelStyle->m_clrColor.m_fAlpha;
+ if(fAlpha == 0.0) return;
+
+ gdouble fTotalX = 0.0;
+ gdouble fTotalY = 0.0;
+
+
+ gdouble fMaxX = -G_MAXDOUBLE; // init to the worst possible value so first point will override
+ gdouble fMaxY = -G_MAXDOUBLE;
+ gdouble fMinX = G_MAXDOUBLE;
+ gdouble fMinY = G_MAXDOUBLE;
+
+ mappoint_t* pMapPoint;
+ gdouble fX;
+ gdouble fY;
+ gint i;
+ for(i=0 ; i<pPointString->m_pPointsArray->len ; i++) {
+ pMapPoint = g_ptr_array_index(pPointString->m_pPointsArray, i);
+
+ fX = SCALE_X(pRenderMetrics, pMapPoint->m_fLongitude);
+ fY = SCALE_Y(pRenderMetrics, pMapPoint->m_fLatitude);
+
+ // find extents
+ fMaxX = max(fX,fMaxX);
+ fMinX = min(fX,fMinX);
+ fMaxY = max(fY,fMaxY);
+ fMinY = min(fY,fMinY);
+
+ // sum up Xs and Ys (we'll take an average later)
+ fTotalX += fX;
+ fTotalY += fY;
+ }
+
+ //
+ gdouble fPolygonHeight = fMaxY - fMinY;
+ gdouble fPolygonWidth = fMaxX - fMinX;
+
+ gdouble fDrawX = fTotalX / pPointString->m_pPointsArray->len;
+ gdouble fDrawY = fTotalY / pPointString->m_pPointsArray->len;
+
+ cairo_save(pCairo);
+
+ cairo_select_font(pCairo, "Monospace",
+ CAIRO_FONT_SLANT_NORMAL,
+ pLabelStyle->m_abBoldAtZoomLevel[pRenderMetrics->m_nZoomLevel-1] ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_scale_font(pCairo, fFontSize);
+
+ // Get total width of string
+ cairo_text_extents_t extents;
+ cairo_text_extents(pCairo, pszLabel, &extents);
+
+ // is the text too big for the polygon?
+ if((extents.width > (fPolygonWidth * 1.5)) || (extents.height > (fPolygonHeight * 1.5))) {
+ cairo_restore(pCairo);
+ return;
+ }
+
+ fDrawX -= (extents.width / 2);
+ fDrawY += (extents.height / 2);
+
+// g_print("drawing at %f,%f\n", fDrawX, fDrawY);
+
+ cairo_move_to(pCairo, fDrawX, fDrawY);
+ cairo_set_rgb_color(pCairo, pLabelStyle->m_clrColor.m_fRed, pLabelStyle->m_clrColor.m_fGreen, pLabelStyle->m_clrColor.m_fBlue);
+ cairo_set_alpha(pCairo, fAlpha);
+ cairo_text_path(pCairo, pszLabel);
+
+ gboolean bDrawHalo = pLabelStyle->m_abHaloAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
+ if(bDrawHalo) {
+ cairo_save(pCairo);
+ cairo_set_line_width(pCairo, 3);
+ cairo_set_rgb_color(pCairo, 1.0,1.0,1.0);
+ cairo_stroke(pCairo);
+ cairo_restore(pCairo);
+ }
+ cairo_fill(pCairo);
+ cairo_restore(pCairo);
+}
// g_print("map (%f,%f)->(%f,%f) screen (%f,%f)->(%f,%f) center (%f,%f)\n",pMapPoint1->m_fLatitude,pMapPoint1->m_fLongitude, pMapPoint2->m_fLatitude,pMapPoint2->m_fLongitude, fX1,fY1, fX2,fY2, fX,fY);
// Calculate line length (in screen pixels)
@@ -1103,7 +1197,7 @@
cairo_restore(pCairo);
}
-void map_draw_layer_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle)
+void map_draw_layer_line_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle)
{
gint iString;
gdouble fLineWidth = pSubLayerStyle->m_afLineWidths[pRenderMetrics->m_nZoomLevel-1];
@@ -1116,6 +1210,20 @@
}
}
+void map_draw_layer_polygon_labels(cairo_t* pCairo, rendermetrics_t* pRenderMetrics, geometryset_t* pGeometry, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle)
+{
+ gint i;
+
+ for(i=0 ; i<pGeometry->m_pPointStringsArray->len ; i++) {
+ pointstring_t* pPointString = g_ptr_array_index(pGeometry->m_pPointStringsArray, i);
+
+ if(pPointString->m_pszName[0] != '\0') {
+ g_print("printing %s\n", pPointString->m_pszName);
+ map_draw_polygon_label(pCairo, pLabelStyle, pRenderMetrics, pPointString, pPointString->m_pszName);
+ }
+ }
+}
+
const gchar* map_road_suffix_itoa(gint nSuffixID, gint nSuffixType)
{
if(nSuffixID >= ROAD_SUFFIX_FIRST && nSuffixID <= ROAD_SUFFIX_LAST) {
Index: searchwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- searchwindow.c 22 Feb 2005 17:12:27 -0000 1.3
+++ searchwindow.c 22 Feb 2005 17:33:14 -0000 1.4
@@ -210,8 +210,6 @@
mainwindow_set_not_busy(&pBusy);
}
-
-
gtk_widget_set_sensitive(GTK_WIDGET(g_SearchWindow.m_pFindButton), TRUE);
}
More information about the cairo-commit
mailing list