Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved angle of text on ways. Fixes #9.

  • Loading branch information...
commit c3747ea149b7db0fe1f6515ad1236b12e07c0bf5 1 parent 5bef7a2
Tom Davie authored
3  OpenStreetPad/Model/API/OSPWay.h
View
@@ -18,7 +18,6 @@
- (OSPCoordinate2D)projectedCentroid;
- (double)length;
-- (CGPoint)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffset backwards:(BOOL)backwards;
-- (CGFloat)angleOnWayWithOffset:(CGFloat)xOffset backwards:(BOOL)backwards;
+- (OSPCoordinate2D)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffset backwards:(BOOL)backwards;
@end
4 OpenStreetPad/Model/API/OSPWay.m
View
@@ -239,7 +239,7 @@ - (double)length
return l;
}
-- (CGPoint)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffset backwards:(BOOL)backwards
+- (OSPCoordinate2D)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffset backwards:(BOOL)backwards
{
[self createEdgeLengthsIfNeeded];
@@ -289,7 +289,7 @@ - (CGPoint)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffse
double xCrawl = prop * dx;
double yCrawl = prop * dy;
- return CGPointMake(prevPointLocation.x + xCrawl, prevPointLocation.y + yCrawl);
+ return OSPCoordinate2DMake(prevPointLocation.x + xCrawl, prevPointLocation.y + yCrawl);
}
- (CGFloat)angleOnWayWithOffset:(CGFloat)xOffset backwards:(BOOL)backwards
39 OpenStreetPad/OSPMetaTileView.m
View
@@ -736,7 +736,31 @@ - (void)drawText:(NSString *)text onWay:(OSPWay *)textWay inContext:(CGContextRe
CTRunRef run = CFArrayGetValueAtIndex(runs, runNumber);
CFIndex numGlyphs = CTRunGetGlyphCount(run);
const CGGlyph *glyphs = CTRunGetGlyphsPtr(run);
- const CGPoint *glyphPositions = CTRunGetPositionsPtr(run);
+ const CGPoint *glyphOffsets = CTRunGetPositionsPtr(run);
+ OSPCoordinate2D *glyphPositions = malloc((numGlyphs + 1) * sizeof(OSPCoordinate2D));
+ CGFloat *glyphAngles = malloc(numGlyphs * sizeof(CGFloat));
+
+ CGPoint currentGlyphOffset;
+ for (CFIndex glyphNumber = 0; glyphNumber < numGlyphs; glyphNumber++)
+ {
+ currentGlyphOffset = glyphOffsets[glyphNumber];
+ glyphPositions[glyphNumber] = [textWay positionOnWayWithOffset:wayOffset + currentGlyphOffset.x heightAboveWay:currentGlyphOffset.y - scaledOffset backwards:backwards];
+ }
+ glyphPositions[numGlyphs] = [textWay positionOnWayWithOffset:wayOffset + lineWidth heightAboveWay:-scaledOffset backwards:backwards];
+ OSPCoordinate2D currentGlyphPosition = glyphPositions[0];
+ for (CFIndex glyphNumber = 0; glyphNumber < numGlyphs; glyphNumber++)
+ {
+ OSPCoordinate2D nextGlyphPosition = glyphPositions[glyphNumber+1];
+
+ double dx = nextGlyphPosition.x - currentGlyphPosition.x;
+ double dy = nextGlyphPosition.y - currentGlyphPosition.y;
+ glyphAngles[glyphNumber] = dx > 0.0 ? (dy > 0.0 ? atan(dy / dx) : -atan(-dy / dx))
+ : dx < 0.0 ? (dy > 0.0 ? M_PI - atan(dy / -dx) : M_PI + atan(-dy / -dx))
+ : (dy < 0.0 ? 3 * M_PI_2 : M_PI_2);
+
+
+ currentGlyphPosition = nextGlyphPosition;
+ }
if (hasHalo)
{
@@ -744,10 +768,9 @@ - (void)drawText:(NSString *)text onWay:(OSPWay *)textWay inContext:(CGContextRe
for (CFIndex glyphNumber = 0; glyphNumber < numGlyphs; glyphNumber++)
{
CGGlyph glyph = glyphs[glyphNumber];
- CGPoint glyphPosition = glyphPositions[glyphNumber];
+ OSPCoordinate2D p = glyphPositions[glyphNumber];
- CGPoint p = [textWay positionOnWayWithOffset:wayOffset + glyphPosition.x heightAboveWay:glyphPosition.y - scaledOffset backwards:backwards];
- CGContextSetTextMatrix(ctx, CGAffineTransformConcat(CGAffineTransformMakeRotation(-[textWay angleOnWayWithOffset:wayOffset + glyphPosition.x backwards:backwards]), CGAffineTransformMakeScale(1.0, -1.0)));
+ CGContextSetTextMatrix(ctx, CGAffineTransformConcat(CGAffineTransformMakeRotation(-glyphAngles[glyphNumber]), CGAffineTransformMakeScale(1.0, -1.0)));
CGContextSetTextPosition(ctx, p.x, p.y);
CGContextShowGlyphs(ctx, &glyph, 1);
}
@@ -756,13 +779,15 @@ - (void)drawText:(NSString *)text onWay:(OSPWay *)textWay inContext:(CGContextRe
for (CFIndex glyphNumber = 0; glyphNumber < numGlyphs; glyphNumber++)
{
CGGlyph glyph = glyphs[glyphNumber];
- CGPoint glyphPosition = glyphPositions[glyphNumber];
+ OSPCoordinate2D p = glyphPositions[glyphNumber];
- CGPoint p = [textWay positionOnWayWithOffset:wayOffset + glyphPosition.x heightAboveWay:glyphPosition.y - scaledOffset backwards:backwards];
- CGContextSetTextMatrix(ctx, CGAffineTransformConcat(CGAffineTransformMakeRotation(-[textWay angleOnWayWithOffset:wayOffset + glyphPosition.x backwards:backwards]), CGAffineTransformMakeScale(1.0, -1.0)));
+ CGContextSetTextMatrix(ctx, CGAffineTransformConcat(CGAffineTransformMakeRotation(-glyphAngles[glyphNumber]), CGAffineTransformMakeScale(1.0, -1.0)));
CGContextSetTextPosition(ctx, p.x, p.y);
CGContextShowGlyphs(ctx, &glyph, 1);
}
+
+ free(glyphPositions);
+ free(glyphAngles);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.