(self, ctx)
| 286 | |
| 287 | |
| 288 | def loadTiles(self, ctx): |
| 289 | |
| 290 | scale = self.scale |
| 291 | sourceTileSize = int(self.sourceTileSize) |
| 292 | |
| 293 | pngSurface = cairo.ImageSurface.create_from_png(self.tilesFileName) |
| 294 | pngWidth = int(pngSurface.get_width()) |
| 295 | pngHeight = int(pngSurface.get_height()) |
| 296 | |
| 297 | nativeTarget = ctx.get_target() |
| 298 | |
| 299 | if scale == sourceTileSize: |
| 300 | |
| 301 | tileSize = sourceTileSize |
| 302 | tilesWidth = pngWidth |
| 303 | tilesHeight = pngHeight |
| 304 | tilesSurface = nativeTarget.create_similar(cairo.CONTENT_COLOR, tilesWidth, tilesHeight) |
| 305 | |
| 306 | tilesCtx = cairo.Context(tilesSurface) |
| 307 | |
| 308 | tilesCtx.set_source_surface(pngSurface, 0, 0) |
| 309 | |
| 310 | tilesCtx.paint() |
| 311 | |
| 312 | else: |
| 313 | |
| 314 | tileSize = max(1, int(math.floor(scale))) |
| 315 | |
| 316 | pngCols = int(math.floor(pngWidth / sourceTileSize)) |
| 317 | pngRows = int(math.floor(pngHeight / sourceTileSize)) |
| 318 | |
| 319 | tilesWidth = tileSize * pngCols |
| 320 | tilesHeight = tileSize * pngRows |
| 321 | |
| 322 | #print "tileSize", tileSize, "pngCols", pngCols, "pngRows", pngRows, "tilesWidth", tilesWidth, "tilesHeight", tilesHeight |
| 323 | |
| 324 | tilesSurface = nativeTarget.create_similar(cairo.CONTENT_COLOR, tilesWidth, tilesHeight) |
| 325 | |
| 326 | tilesCtx = cairo.Context(tilesSurface) |
| 327 | |
| 328 | # Clip and convert each tile through this server side 565 surface. |
| 329 | #tileSurface = nativeTarget.create_similar(cairo.CONTENT_COLOR, sourceTileSize, sourceTileSize) |
| 330 | |
| 331 | # Clip each tile through this client side 888 surface. |
| 332 | tileSurface = pngSurface.create_similar(cairo.CONTENT_COLOR, sourceTileSize, sourceTileSize) |
| 333 | |
| 334 | tileCtx = cairo.Context(tileSurface) |
| 335 | |
| 336 | for row in range(0, pngRows): |
| 337 | for col in range(0, pngCols): |
| 338 | # Make a temporary tile size of a source tile. |
| 339 | tileCtx.set_source_surface( |
| 340 | pngSurface, |
| 341 | -col * sourceTileSize, |
| 342 | -row * sourceTileSize) |
| 343 | tileCtx.paint() |
| 344 | |
| 345 | # Scale it down into the tilesSurface. |
no test coverage detected