discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cairo drawing problem


From: Josh Freeman
Subject: Re: cairo drawing problem
Date: Wed, 10 Jun 2020 18:05:39 -0400

Hi Andreas,

Try initializing your window as NSBackingStoreBuffered? (NSBackingStoreNonretained tells the window to draw directly to the screen without buffering, so the pixel data is probably unavailable for reading back).

Cheers,

Josh


On Jun 8, 2020, at 1:52 PM, Andreas Höschler via Discussion list for the GNUstep programming environment wrote:


Hi all,

I have just found some time to continue testing my app(s) on GNUstep and realised that drawing OSM maps fails under GNUstep when using the cairo backend while it works if using libart.

My code draws something in a NSView subclass and then uses

         [mapView display];
         [mapView lockFocus];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[mapView bounds]]; data = [[[rep representationUsingType:NSPNGFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease];
         if ([data length] == 0) // try TIFF instead
           {
data = [[[rep representationUsingType:NSTIFFFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease]; if ([data length] == 0) NSLog(@"Damn! TIFF failed as well!");
           }
         [mapView unlockFocus];

to produce a PNG from the view content. This works great with libart

art:
= = = = = = ======================================================================

2020-06-08 19:37:18.526 ESMMapServer[10165:10165] draw way inlays... 359 _drawPrimaryInLays 1 _drawOtherInLays 1
2020-06-08 19:37:18.527 ESMMapServer[10165:10165] BUMM
2020-06-08 19:37:18.545 ESMMapServer[10165:10165] Draw 7 mapShields ...
2020-06-08 19:37:18.548 ESMMapServer[10165:10165] Draw 1 mapLocs ...
2020-06-08 19:37:18.549 ESMMapServer[10165:10165] Draw 2 mapLines ...
2020-06-08 19:37:18.549 ESMMapServer[10165:10165] <ESMMapLine: 0x2ed0550> drawLine _colorName (null) _color 0 0 1 2020-06-08 19:37:18.549 ESMMapServer[10165:10165] <ESMMapLine: 0x2ed4610> drawLine _colorName (null) _color 0 1 0 2020-06-08 19:37:18.557 ESMMapServer[10165:10165] h=--- v=--- <ESMMapView: 0x2302ca0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; width = 542; height = 620} locking Focus ...
2020-06-08 19:37:18.557 ESMMapServer[10165:10165] getting rep ...
2020-06-08 19:37:18.563 ESMMapServer[10165:10165] rep <NSBitmapImageRep: 0x2f15450 size: {width = 542; height = 620} pixelsWide: 542 pixelsHigh: 620 colorSpaceName: NSDeviceRGBColorSpace bps: 8> 2020-06-08 19:37:18.665 ESMMapServer[10165:10165] h=--- v=--- <ESMMapView: 0x2302ca0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; width = 542; height = 620} unocked Focus!
2020-06-08 19:37:18.665 ESMMapServer[10165:10165] data 248529

but fails with cairo

cairo:
= = = = = = = = = = = = = = = = = ====================================================================== 2020-06-08 19:31:52.783 ESMMapServer[9982:9982] draw way inlays... 359 _drawPrimaryInLays 1 _drawOtherInLays 1
2020-06-08 19:31:52.783 ESMMapServer[9982:9982] BUMM
2020-06-08 19:31:52.798 ESMMapServer[9982:9982] Draw 8 mapShields ...
2020-06-08 19:31:52.801 ESMMapServer[9982:9982] Draw 1 mapLocs ...
2020-06-08 19:31:52.802 ESMMapServer[9982:9982] Draw 2 mapLines ...
2020-06-08 19:31:52.802 ESMMapServer[9982:9982] <ESMMapLine: 0x33b52c0> drawLine _colorName (null) _color 0 0 1 2020-06-08 19:31:52.802 ESMMapServer[9982:9982] <ESMMapLine: 0x33c3d30> drawLine _colorName (null) _color 0 1 0 2020-06-08 19:31:52.811 ESMMapServer[9982:9982] h=--- v=--- <ESMMapView: 0x28e0fe0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; width = 542; height = 620} locking Focus ...
2020-06-08 19:31:52.812 ESMMapServer[9982:9982] getting rep ...
2020-06-08 19:31:52.815 ESMMapServer[9982:9982] rep <NSBitmapImageRep: 0x3698ef0 size: {width = 542; height = 620} pixelsWide: 542 pixelsHigh: 620 colorSpaceName: NSDeviceRGBColorSpace bps: 8> 2020-06-08 19:31:52.882 ESMMapServer[9982:9982] h=--- v=--- <ESMMapView: 0x28e0fe0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; width = 542; height = 620} unocked Focus!
2020-06-08 19:31:52.883 ESMMapServer[9982:9982] data 1383
2020-06-08 19:31:52.921 ESMMapServer[9982:9982] X-Windows error - RenderBadPicture (invalid Picture parameter)
          on display: :0
                type: 0
       serial number: 1169
        request code: 139


data contains nothing reasonable after this X-WIndows error. I have attached the complete implementation of

- (NSDictionary *)PNGForMapRequestDic:(NSDictionary *)dic;

for reference below (contains the lockFocus ... unlockFocus magic). Any idea what might be causing this X-Windows error with cairo? I am stuck when it gets to backend issues. I might have to add that this error occurs in a tool (no gui app) named ESMMapServer which is supposed to produce maps (PNGs) from OSM data in the background.

Thanks a lot,

 Andreas







- (NSDictionary *)PNGForMapRequestDic:(NSDictionary *)dic
{
   NSNumber *pixelWidth = [dic objectForKey:@"pixelWidth"];
   NSNumber *pixelHeight = [dic objectForKey:@"pixelHeight"];
   NSNumber *x = [dic objectForKey:@"x"];
   NSNumber *y = [dic objectForKey:@"y"];
   NSNumber *width = [dic objectForKey:@"width"];
   NSNumber *height = [dic objectForKey:@"height"];
   NSArray *locations = [dic objectForKey:@"locations"];
   NSArray *hintPaths = [dic objectForKey:@"hintPaths"];
BOOL drawTextMarks = [[dic objectForKey:@"drawTextMarks"] intValue]; NSLog(@"PNGForMapRequestDic hintPaths %d %@ %@ %@ %@ pixelWidth %@ pixelHeight %@", [hintPaths count], x, y, width, height, pixelWidth, pixelHeight);
   NSLog(@"locations %@", [locations description]);

   [_shields removeAllObjects];

if ((pixelWidth) && (pixelHeight) && (x) && (y) && (width) && (height))
     {
_visibleMapSection = NSMakeRect ([x floatValue], [y floatValue], [width floatValue], [height floatValue]); if (_visibleMapSection.size.height > MAXESMMAPHEIGHT) // reducing map size to avoid OSMMapServer break down <-----------
        {
NSLog(@"reducing map size to avoid OSMMapServer break down %f -> %f", _visibleMapSection.size.height, MAXESMMAPHEIGHT); float margin = (_visibleMapSection.size.height - MAXESMMAPHEIGHT) / 2;
         _visibleMapSection.origin.y += margin;
         _visibleMapSection.size.height = MAXESMMAPHEIGHT;
        }
_imageSize = NSMakeSize([pixelWidth floatValue], [pixelHeight floatValue]);
      NSLog(@"_imageSize %@", NSStringFromSize(_imageSize));
if (_imageSize.width / _imageSize.height > (_visibleMapSection.size.width * cos ((_visibleMapSection.origin.y + _visibleMapSection.size.height / 2.0) / 180.0 * 3.14)) / _visibleMapSection.size.height)
        {
float correctedWidth = _visibleMapSection.size.height * _imageSize.width / (_imageSize.height * cos ((_visibleMapSection.origin.y + _visibleMapSection.size.height / 2.0) / 180.0 * 3.14)); // NSLog(@"requested width %f correctedWidth %f", _visibleMapSection.size.width, correctedWidth); _visibleMapSection.origin.x -= (correctedWidth - _visibleMapSection.size.width) / 2.0;
         _visibleMapSection.size.width = correctedWidth;
        }
      else
        {
float correctedHeight = (_visibleMapSection.size.width * _imageSize.height * cos ((_visibleMapSection.origin.y + _visibleMapSection.size.height / 2.0) / 180.0 * 3.14) / _imageSize.width); // NSLog(@"requested height %f correctedHeight %f", _visibleMapSection.size.height, correctedHeight); _visibleMapSection.origin.y -= (correctedHeight - _visibleMapSection.size.height) / 2.0;
         _visibleMapSection.size.height = correctedHeight;
        }
NSLog(@"_visibleMapSection %@", NSStringFromRect(_visibleMapSection));

NSArray *presentations = [self suitablePresentationsForRect:_visibleMapSection];
      //      NSLog(@"presentations %@", [presentations description]);
      NSEnumerator *enumerator = [presentations objectEnumerator];
      ESMMapPresentation *presentation;
      NSArray *highways = nil;
      NSArray *ways = nil;
      NSArray *namedNodes = nil;
      ESMMapView *mapView = nil;
      NSWindow *window = nil;

      NSLog(@"_sharedMapView %@", _sharedMapView);
      if (_sharedMapView)
        {
         mapView = (ESMMapView *)[_sharedMapView retain];
         [mapView removeAllPathsAndMapLabels];
        }
      else
        {
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0, _imageSize.width, _imageSize.height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO]; mapView = [[ESMMapView alloc] initWithFrame:NSMakeRect(0, 0, _imageSize.width, _imageSize.height)];
//         NSLog(@"window %@", window);
         //         [window setContentView:mapView];
         [[window contentView] addSubview:mapView];
// [window setContentSize:NSMakeSize(_imageSize.width * 0.5, _imageSize.height *0.5)]; // <--- superfluous // NSLog(@"mapView %@ bounds %@", NSStringFromRect([mapView frame]), NSStringFromRect([mapView bounds]));
//         NSView *clipView = [mapView superview];
// NSLog(@"clipView %@ bounds %@", NSStringFromRect([clipView frame]), NSStringFromRect([clipView bounds]));
        }
      [mapView prepareOSMDrawing];
[mapView setVisibleMapSection:_visibleMapSection]; // used to determine zoom level / how to render streets, draw labels etc.
      //      NSSize unitSize = {1.0, 1.0};
// [mapView scaleUnitSquareToSize:[mapView convertSize:unitSize fromView:nil]];

#ifdef LOADCOSTLINES
      if (_visibleMapSection.size.height > 8.0)
        {
         if (!_roughShapeFile)
           {
// NSString *path = [NSBundle pathForResource:@"germany" ofType:@"shp"]; NSString *path = [NSBundle pathForResource:@"worldland- low" ofType:@"shp"];
            NSLog(@"_roughShapeFile path %@", path);
            if (path)
              {
_roughShapeFile = [[ESMShapeFile alloc] initWithPath:path];
               [_roughShapeFile loadShapeFile];
              }
           }
NSLog(@"_roughShapeFile %@ --> calcing bezierPathsForVisibleMapSectionc ...", _roughShapeFile); [mapView setBezierPathsForLand:[_roughShapeFile bezierPathsForVisibleMapSection:_visibleMapSection imageSize:_imageSize]];
         NSLog(@"Done");
        }
      else
        {
         if (!_fineShapeFile)
           {
// NSString *path = [NSBundle pathForResource:@"germany" ofType:@"shp"]; NSString *path = [NSBundle pathForResource:@"worldland- high" ofType:@"shp"];
            NSLog(@"_fineShapeFile path %@", path);
            if (path)
              {
_fineShapeFile = [[ESMShapeFile alloc] initWithPath:path];
               [_fineShapeFile loadShapeFile];
              }
           }
NSLog(@"_fineShapeFile %@ --> calcing bezierPathsForVisibleMapSectionc ...", _fineShapeFile); [mapView setBezierPathsForLand:[_fineShapeFile bezierPathsForVisibleMapSection:_visibleMapSection imageSize:_imageSize]];
         NSLog(@"Done");
        }
      #endif

// [mapView setDrawlInLays:[mapView heightOfVisibleMapInKm] < 5.0];

// NSLog(@"Iterating through %d presentations ...", [presentations count]);
      while (presentation = [enumerator nextObject])
        {
// [mapView setDrawlInLays:[presentation shouldDrawInlays]];

// presentation returns only those ways and highways that should be drawn respecting the detail level of the presentation
         NSLog(@"Getting mapTiles ...");
NSArray *mapTiles = [presentation mapTilesForVisibleMapSection:_visibleMapSection highways:&highways ways:&ways namedNodes:&namedNodes];
         NSLog(@"We are utilizing %d mapTiles ...", [mapTiles count]);

         /* *** add ESMMapLabels to mapView *** */
           {
            NSEnumerator *enumerator = [namedNodes objectEnumerator];
            KindNode *node;
            while (node = [enumerator nextObject])
              {
// NSLog(@"Creating mapLabel for %@ %@ %@ %@", node, [node valueForKey:@"name"], [node valueForKey:@"x"], [node valueForKey:@"y"]); NSPoint point = [self pixelFromGPS:NSMakePoint([[node valueForKey:@"x"] floatValue], [[node valueForKey:@"y"] floatValue])]; // ESMMapLabel *mapLabel = [[ESMMapLabel alloc] initWithPoint:point name:[node valueForKey:@"name"] kind:[ESMMapLabel nodekindForString:[node valueForKey:@"kind"]]]; ESMMapLabel *mapLabel = [[ESMMapLabel alloc] initWithPoint:point name:[node valueForKey:@"name"] kind:node->_kind];
               //               [mapView addMapLabel:mapLabel];
               [mapView->_mapLabels addObject:mapLabel];
               [mapLabel release];
              }
           }

         #ifndef BLENDAHIGHWAY

         /* *** add ESMMapPaths for the highways *** */
           {
NSLog(@"Iterating through %d highways ...", [highways count]);
            NSEnumerator *enumerator = [highways objectEnumerator];
            Highway *highway;
            int currentKind = -1;
            NSString *currentName = nil;
            ESMMapPath *currentPath = nil;
            NSBezierPath *currentBezier = nil;
            unsigned pathCounter = 0;
BOOL tooBigForSmallStreets = (_visibleMapSection.size.height > MAXHEIGHTFORSMALLSTREET); BOOL tooBigForTrunkStreets = (_visibleMapSection.size.height > MAXHEIGHTFORTRUNKSTREET); BOOL tooBigForSmallMotorways = (_visibleMapSection.size.height > MAXHEIGHTFORSMALLMOTORWAYS); // NSLog(@"add ESMMapPaths for the highways ...");

            while (highway = [enumerator nextObject])
              {
// BOOL debug = ([highway integerForKey:@"publicID"] < 0); // BOOL debug = NO;// [[highway valueForKey:@"name"] isEqualToString:@"Muellerweg"]; // int kind = [ESMMapPath waykindForString:[highway valueForKey:@"highway"]];
               int kind = highway->_kind;
               //               BOOL debug = (kind == ESMWK_MOTORWAY);
//               NSLog(@"highway %@ kind %d", highway, kind);
               if (kind == -1 || kind == NSNotFound) continue;
               if (kind == ESMWK_UNCLASSIFIED)
                 {
// NSLog(@"ESMWK_UNCLASSIFIED highway %@", [highway valueForKey:@"publicID"]);
                 }
if (tooBigForSmallStreets && kind > ESMWK_TERTIARY) continue; if (tooBigForTrunkStreets && kind > ESMWK_MOTORWAY) continue; NSString *ref = [highway valueForKey:@"ref"]; // <--- ???
//               BOOL debug = [ref isEqualToString:@"L 71"];
if (tooBigForSmallMotorways && kind == ESMWK_MOTORWAY && [[(NSString *)[highway valueForKey:@"ref"] substringFromIndex:1] intValue] > 24) continue; if (tooBigForSmallStreets && kind == ESMWK_MOTORWAYLINK)
                 {
if ((highway->_rect.top - highway->_rect.bottom) / _visibleMapSection.size.height < 0.05 && (highway->_rect.right - highway->_rect.left) / _visibleMapSection.size.width < 0.05) continue;
                 }

               NSArray *nodesArray = [highway nodesArray];
               int i, count = [nodesArray count];
               //               NSLog(@"nodesArray count %d", count);
               if (count < 2) continue;

// if (ref) NSLog(@"doll highway %@ count %d kind %d name %@ ref %@", highway, count, kind, [highway valueForKey:@"name"], ref);

               NSString *name = [highway valueForKey:@"name"];
               BOOL currentPathIsClosedPath;
               NSPoint pixelStartPoint;

if (currentKind != kind || [currentName isEqualToString:highway->_sortName] == NO)
                 {
currentPath = [[ESMMapPath alloc] initWithKind:kind name:name]; // if (debug) NSLog(@"currentPath %@ name %@ ref %@ new currentBezier", currentPath, name, ref);
                  // [mapView addMapPath:currentPath];
                  [mapView->_mapPaths addObject:currentPath];
                  currentKind = kind;
                  //                  currentName = name;
                  currentName = highway->_sortName;
                  pathCounter++;
                  [currentPath release];
                  currentBezier = [currentPath bezierPath];
                 }
               currentPathIsClosedPath = [currentPath isClosedPath];

               // create label
if (name != nil && [name length] > 0) // create MapLabel for the street name
                 {
                  BOOL drawLabel = NO;

switch (kind) // suppress street label for very small highways
                    {
                     case ESMWK_MOTORWAY:
                     case ESMWK_TRUNK:
                     drawLabel = YES;
                     break;

                     case ESMWK_PRIMARY:
                     case ESMWK_SECONDARY:
                       {
drawLabel = (_visibleMapSection.size.height < MAXHEIGHTFORPRIMARYLABELS);
                       }
                     break;

                     default:
drawLabel = (_visibleMapSection.size.height < MAXHEIGHTFORSTREETLABELS);
                     break;
                    }

                  if (drawLabel)
                    {
                     NSPoint firstPoint, secondPoint;
BOOL success = [ESMMapLabel firstPoint:&firstPoint secondPoint:&secondPoint nodes:nodesArray];
                     if (success)
                       {
                        NSPoint anchor;
                        float angle;
NSRect labelRect = [ESMMapLabel labelRectForString:name firstPoint:[self pixelFromGPS:firstPoint] lastPoint:[self pixelFromGPS:secondPoint] anchor:&anchor angle:&angle];
                        if (labelRect.size.width > 0)
                          {
ESMMapLabel *mapLabel = [[ESMMapLabel alloc] initWithPoint:anchor name:name kind:-1]; // -1 means street label
                           [mapLabel setAngle:angle];
                           [mapLabel setLabelRect:labelRect];
                           // [mapView addMapLabel:mapLabel];
                           [mapView->_mapLabels addObject:mapLabel];
                           [mapLabel release];
                          }
// else NSLog(@"%@ suppressed!", name);
                       }
                    }
                 }

               BOOL gotStarted = NO;
               for (i = 0 ; i < count; i++)
                 {
                  ESMNode *node = [nodesArray objectAtIndex:i];
                  NSPoint gpsPoint = node->_point;
                  NSPoint point = [self pixelFromGPS:gpsPoint];

                  if (gotStarted == NO)
                    {
                     pixelStartPoint = point;
                    }

                  #ifndef BLENDAWAY
if (gotStarted && ref != nil && i > 0 && ((i-1) % 5) == 0) // shield generation
                    {
NSEnumerator *enumerator = [_shields objectEnumerator];
                     NSDictionary *dic;
                     BOOL accept = YES;

// if (debug) NSLog(@"check if an existingShield is too close ...");
                     // check if an existingShield is too close
                     while (dic = [enumerator nextObject])
                       {
NSPoint extPoint = NSPointFromString([dic objectForKey:@"point"]);
                        float dx = point.x - extPoint.x;
                        float dy = point.y - extPoint.y;
                        float r = sqrt (dx * dx + dy * dy);
                        if (r < PIXELDISTANCEBETWEENSHIELDS)
                          {
// NSLog(@"ref %@ i %d shield too close r %f / %f", ref, i, r, PIXELDISTANCEBETWEENSHIELDS);
                           accept = NO;
                           break;
                          }
                       }
// if (debug) NSLog(@"accept %d kind %@", accept, [ESMMapPath stringForWaykind:kind]);
                     if (accept)
                       {
                        NSColor *bezierColor = nil;
                        switch (kind)
                          {
                           case ESMWK_MOTORWAY:
                           case ESMWK_MOTORWAYLINK:
                           bezierColor = [ESMMapView motorWayColor];
                           break;

                           case ESMWK_PRIMARY:
                           case ESMWK_PRIMARYLINK:
                           bezierColor = [ESMMapView primaryColor];
                           break;

                           case ESMWK_TRUNK:
                           case ESMWK_TRUNKLINK:
                           bezierColor = [ESMMapView trunkColor];
                           break;

                           case ESMWK_SECONDARY:
bezierColor = [ESMMapView secondaryShieldColor];
                           break;

                           default:
                           break;
                          }
// NSLog(@"ref %@ kind %@ %d bezierColor %@", ref, [ESMMapPath stringForWaykind:kind], kind, bezierColor);
                        #ifndef SUPPRESSSHIELDS
                        if (bezierColor)
                          {
ESMMapShield *mapShield = [[ESMMapShield alloc] initWithPoint:point ref:[ref stringAfterRemovingAllOccurencesOfString:@" "] color:bezierColor]; // NSLog(@"Adding mapShield for ref %@ at %@", ref, NSStringFromPoint(point)); // [mapView addMapShield:mapShield];
                           [mapView->_mapShields addObject:mapShield];
                           [mapShield release];

NSDictionary *someDic = [[NSDictionary alloc] initWithObjectsAndKeys:NSStringFromPoint(point), @"point", ref, @"ref", nil];
                           [_shields addObject:someDic];
                           [someDic release];
                          }
                        #endif
                       }
                    }
                  #endif

                  if (gotStarted == NO)
                    {
// if (debug) NSLog(@"moveToPoint: %@", NSStringFromPoint(point));
                     [currentBezier moveToPoint:point];
                     gotStarted = YES;
                    }
                  else if (currentPathIsClosedPath && i == count -1)
                    {
// if (debug) NSLog(@"lineToPoint: %@", NSStringFromPoint(pixelStartPoint)); // [currentBezier lineToPoint:pixelStartPoint]; // return to exact start point
                     [currentBezier closePath];
                    }
                  else
                    {
// if (debug) NSLog(@"lineToPoint: %@", NSStringFromPoint(point)); /* if (pixelLastPoint.x == point.x && pixelLastPoint.y == point.y)
                       {
// NSLog(@"Suppress line to same point %@ i: %d", NSStringFromPoint(point), i);
                       }
                     else*/ [currentBezier lineToPoint:point];
                    }
                 }
              }
           }
         #endif

         #ifndef BLENDAWAY
         /* *** add ESMMapPaths for the ways (buildings ...) *** */
           {
            NSLog(@"Iterating through %d ways ...", [ways count]);
            NSEnumerator *enumerator = [ways objectEnumerator];
            Way *way;
            int currentKind = -1;
            ESMMapPath *currentPath = nil;
            NSBezierPath *currentBezier = nil;
            unsigned pathCounter = 0;

            while (way = [enumerator nextObject])
              {
               NSArray *nodesArray = [way nodesArray];
               NSString *name = [way valueForKey:@"name"];
//               if (name) NSLog(@"hit named way %@", name);
               int i, count = [nodesArray count];
// NSString *kindString = [way valueForKey:@"kind"]; // if (kindString == nil) { NSLog(@"way %@ has no kind!??", [way keyValueDic]); continue; } // int kind = [ESMMapPath waykindForString:kindString];
               int kind = way->_kind;
// NSLog(@"way %@ kind %d count %d string %@", way, kind, count, [ESMMapPath stringForWaykind:kind]);
               BOOL debug = NO;//(kind == ESMWK_BUILDING);
// if (debug) NSLog(@"Bumahh, encountered ESMWK_BUILDING");
               BOOL currentPathIsClosedPath;
               NSPoint pixelStartPoint;

               if (kind == -1 || kind == NSNotFound) continue;
// if (kind == ESMWK_UNCLASSIFIED) NSLog(@"way %@", [way valueForKey:@"publicID"]);

               /*#ifndef __APPLE__
               switch (kind)
                 {
                  case ESMWK_RAILWAYCONSTRUCTION:
                  case ESMWK_RAILWAYRAIL:
                  case ESMWK_RAILWAYABANDONEDTRAM:
                  case ESMWK_RAILWAYTRAM:
                  case ESMWK_RAILWAYABANDONED:
                  case ESMWK_RAILWAYPLATFORM:
                  continue;
                  default:
                  break;
                 }
// if ([[kindString uppercaseString] rangeOfString:@"RAIL"].length > 0) continue; // railways cause noise problems on GNUstep with libart
               #endif
               */

               if (currentKind != kind)
                 {
currentPath = [[ESMMapPath alloc] initWithKind:kind name:nil]; // if (isCoastline) NSLog(@"created currentPath %@", currentPath); // [mapView addMapPath:currentPath];
                  [mapView->_mapPaths addObject:currentPath];
if (debug) NSLog(@"Added currentPath to mapPaths ...");
                  currentKind = kind;
                  pathCounter++;
                  [currentPath release];
                  currentBezier = [currentPath bezierPath];
                 }
               currentPathIsClosedPath = [currentPath isClosedPath];

               // handle nodes
               BOOL gotStarted = NO;
               for (i = 0 ; i < count; i++)
                 {
                  ESMNode *node = [nodesArray objectAtIndex:i];
                  NSPoint gpsPoint = node->_point;
BOOL pointVisible = NSPointInRect(gpsPoint, _visibleMapSection); if (!pointVisible) // gpsPoint liegt ausserhalb von _visibleMapSection
                    {
                     //                     continue;
                    }
                  NSPoint point = [self pixelFromGPS:gpsPoint];
                  if (gotStarted == NO)
                    {
                     pixelStartPoint = point;
                    }

                  if (gotStarted == NO)
                    {
// NSLog(@"moveToPoint: %@", NSStringFromPoint(point));
                     [currentBezier moveToPoint:point];
                     gotStarted = YES;
                    }
                  else if (currentPathIsClosedPath && i == count -1)
                    {
// NSLog(@"lineToPoint: %@", NSStringFromPoint(point)); // [currentBezier lineToPoint:pixelStartPoint]; // return to exact start point
                     [currentBezier closePath];
                    }
                  else
                    {
// NSLog(@"lineToPoint: %@", NSStringFromPoint(point));
                     [currentBezier lineToPoint:point];
                    }
                 }




               // create label
if (name != nil && [name length] > 0) // create MapLabel for the street name
                 {
// BOOL drawLabel = (_visibleMapSection.size.height < MAXHEIGHTFORPRIMARYLABELS); BOOL drawLabel = (_visibleMapSection.size.height < MAXHEIGHTFORWAYLABELS);
//                  NSLog(@"drawLabel %d", drawLabel);
                  if (drawLabel)
                    {
NSPoint center = [ESMMapLabel centerPointForNodes:nodesArray]; ESMMapLabel *mapLabel = [[ESMMapLabel alloc] initWithPoint:[self pixelFromGPS:center] name:name kind:NODEKIND_VILLAGE]; // -1 means street label NSSize size = [name sizeWithAttributes: [mapLabel attributes]]; [mapLabel movePointBy:NSMakePoint(-size.width / 3, 0)];
                     [mapLabel setAngle:0]; // angle
                     [mapView->_mapLabels addObject:mapLabel];
                     [mapLabel release];
                    }
                 }




              }
           }


         /* *** add ESMMapLocs to mapView *** */
           {
            NSEnumerator *enumerator = [locations objectEnumerator];
            NSDictionary *dic;
            while (dic = [enumerator nextObject])
              {
               NSString *mark = [dic objectForKey:@"mark"];
               NSString *bitmap = [dic objectForKey:@"bitmap"];
               NSLog(@"mark %@ bitmap %@", mark, bitmap);
               NSNumber *x = [dic objectForKey:@"x"];
               NSNumber *y = [dic objectForKey:@"y"];
               NSNumber *direction = [dic objectForKey:@"direction"];
               NSLog(@"mark %@ direction %@", mark, direction);
               if ((x) && (y) && (bitmap))
                 {
NSPoint point = [self pixelFromGPS:NSMakePoint([x floatValue], [y floatValue])]; ESMMapLoc *mapLoc = [[ESMMapLoc alloc] initWithPoint:point mark:((mark) && drawTextMarks ? mark : @"P") bitmap:bitmap];
                  //                  [mapView addMapLoc:mapLoc];
                  [mapView->_mapLocs addObject:mapLoc];
                  [mapLoc release];
                 }
              }
           }

         /* *** add hint paths to mapView *** */
           {
            NSEnumerator *enumerator = [hintPaths objectEnumerator];
            NSDictionary *dic;
// NSLog(@"add hint paths to mapView %d", [hintPaths count]);
            while (dic = [enumerator nextObject])
              {
NSColor *color = [SRHintPath colorFromColorString: [dic objectForKey:@"colorString"]]; BOOL drawArrows = [[dic objectForKey:@"drawArrows"] isEqualToString:@"YES"]; NSLog(@"colorString %@ color %@ drawArrows %d", [dic objectForKey:@"colorString"], color, drawArrows); ESMMapLine *mapLine = ((color) ? [[ESMMapLine alloc] initWithColor:color] : [[ESMMapLine alloc] initWithColorName:[dic objectForKey:@"dominantColorName"]]);
               NSArray *nodes = [dic objectForKey:@"nodes"];
               NSEnumerator *enumerator = [nodes objectEnumerator];
               NSDictionary *dic;
               int count = [nodes count];
               int counter = 0;
               int margin = count / 10;
               if (margin == 0) margin = 1;
               while (dic = [enumerator nextObject])
                 {
                  NSNumber *x = [dic objectForKey:@"x"];
                  NSNumber *y = [dic objectForKey:@"y"];
                  if ((x) && (y))
                    {
NSPoint point = [self pixelFromGPS:NSMakePoint([x floatValue], [y floatValue])];
                     [mapLine addPoint:point];
                    }
                  counter++;
                  if (drawArrows && counter > margin)
                    {
                     [mapLine addArrow];
                     counter = 0;
                    }
                 }
               [mapView->_mapLines addObject:mapLine];
               [mapLine release];
              }
           }
         #endif

        }
      if ([presentations count])
        {
         [mapView sortMapPaths];
         [mapView sortMapLabels];
        }

      //      NSLog(@"going to display ...");
      //      if (_sharedMapView) [mapView setImage:nil];
      //      NSLog(@"going to lockFocus ...");
// NSLog(@"convertSize %@", NSStringFromSize([mapView convertSize:unitSize toView:nil]));
      NSData *data = nil;

      if (_sharedMapView)
        {
         [mapView prepareOSMDrawing];
         NSLog(@"%@ calling display ..", mapView);
         [mapView display];
         NSLog(@"%@ display done", mapView);
        }
      else
        {
         [mapView display];
         NS_DURING
         NSLog(@"%@ locking Focus ...", mapView);
         [mapView lockFocus];
         NSLog(@"getting rep ...");
// NSLog(@"window frame %@", NSStringFromRect([[mapView window] frame])); // NSLog(@"contentView frame %@", NSStringFromRect([[[mapView window] contentView] frame])); // NSLog(@"frame %@", NSStringFromRect([mapView frame])); // NSLog(@"bounds %@", NSStringFromRect([mapView bounds])); NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[mapView bounds]];
         NSLog(@"rep %@", rep);
data = [[[rep representationUsingType:NSPNGFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease];
/*           {
            NSString *path = @"/home/ahoesch/A.tiff";
NSData *data = [[[rep representationUsingType:NSTIFFFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease];
            [data writeToFile:path atomically:YES];
           }
  */
         if ([data length] == 0) // try TIFF instead
           {
NSLog(@"Getting PNG data failed! We try TIFF instead ..."); // NSData *data = [[[rep TIFFRepresentation] retain] autorelease]; data = [[[rep representationUsingType:NSTIFFFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"NSImageInterlaced"]] retain] autorelease]; if ([data length] == 0) NSLog(@"Damn! TIFF failed as well!");
           }
         [mapView unlockFocus];
         NSLog(@"%@ unocked Focus!", mapView);
         [rep release];
         NS_HANDLER
NSLog(@"Something went terribly wrong: %@", [localException description]);
         //      NSView *clipView = [mapView superview];
// NSLog(@"clipView %@ bounds %@", NSStringFromRect([clipView frame]), NSStringFromRect([clipView bounds]));
         NS_ENDHANDLER
        }

      NSLog(@"data %d", [data length]);
      [window release];
      [mapView release];
      return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:_visibleMapSection.origin.x], @"visibleMapSection.origin.x", [NSNumber numberWithFloat:_visibleMapSection.origin.y], @"visibleMapSection.origin.y", [NSNumber numberWithFloat:_visibleMapSection.size.width], @"visibleMapSection.size.width", [NSNumber numberWithFloat:_visibleMapSection.size.height], @"visibleMapSection.size.height",
      data, @"imageData",
      nil];
     }
   else return nil;
}




Mit freundlichen Grüßen,

Andreas Höschler
Managing Director

Smartsoft GmbH
Birkenweg 11a
D-21483 Gülzow

Phone  040 22820930-0
Fax      040 22820930-9
Web    http://www.smartsoft.de
Email: ahoesch@smartsoft.de

Steuernummer: 44/759/00826
Amtsgericht Hamburg, HRB 117172
Geschäftsführer: Andreas Höschler





reply via email to

[Prev in Thread] Current Thread [Next in Thread]