def rimward_sector(self, pdf, name): cursor = PDFCursor(306, 767, True) def_font = pdf.get_font() pdf.set_font('times', size=10) cursor.x_plus(-pdf.get_font()._string_width(name) / 2) pdf.add_text(name, cursor) pdf.set_font(font=def_font)
def TestCursor(): cursor1 = PDFCursor(20, 30) cursor2 = PDFCursor(22, 50) #print "Should be True:", cursor1 < cursor2 print "Should be False: ", cursor1 > cursor2 print "Should be False: ", cursor1 == cursor2
def coreward_sector(self, pdf, name): cursor = PDFCursor(5, self.y_start - 15, True) def_font = pdf.get_font() pdf.set_font('times', size=10) width = pdf.get_font()._string_width(name) / 2 cursor.x = 306 - width pdf.add_text(name, cursor) pdf.set_font(font=def_font)
def sector_name(self, pdf, name): cursor = PDFCursor(5, -5, True) def_font = pdf.get_font() pdf.set_font('times', size=30) width = pdf.get_font()._string_width(name) cursor.x = 306 - (width / 2) pdf.add_text(name, cursor) pdf.set_font(font=def_font)
def trailing_sector(self, pdf, name): cursor = PDFCursor(598, 396 - self.y_start, True) def_font = pdf.get_font() pdf.set_font('times', size=10) cursor.y_plus(-(pdf.get_font()._string_width(name) / 2)) text = PDFText(pdf.session, pdf.page, None, cursor=cursor) text.text_rotate(-90) text._text(name) pdf.set_font(font=def_font)
def spinward_sector(self, pdf, name): cursor = PDFCursor(self.x_start - 5, 390, True) def_font = pdf.get_font() pdf.set_font('times', size=10) cursor.y_plus(pdf.get_font()._string_width(name) / 2) text = PDFText(pdf.session, pdf.page, None, cursor=cursor) text.text_rotate(90) text._text(name) pdf.set_font(font=def_font)
def trailing_sector(self, pdf, name): cursor = PDFCursor(598, 390, True) def_font = pdf.get_font() pdf.set_font('times', size=10) cursor.y_plus(-(pdf.get_font()._string_width(name) / 2)) text = PDFText(pdf.session, pdf.page, None, cursor=cursor) text.text_rotate(-90) text._text(name) pdf.set_font(font=def_font)
def spinward_sector(self, pdf, name): cursor = PDFCursor(self.x_start - 5, 396, True) def_font = pdf.get_font() pdf.set_font('times', size=10) cursor.y_plus(pdf.get_font()._string_width(name) / 2) text = PDFText(pdf.session, pdf.page, None, cursor=cursor) text.text_rotate(90) text._text(name) pdf.set_font(font=def_font)
def sector_name(self, doc, name): """ Write name at the top of the document """ cursor = PDFCursor(5, -5, True) def_font = doc.get_font() doc.set_font('times', size=30) width = doc.get_font()._string_width(name) cursor.x = 306 - (width / 2) doc.add_text(name, cursor) doc.set_font(font=def_font)
def comm_line(self, pdf, edge): start = edge[0] end = edge[1] color = pdf.get_color() color.set_color_by_number(102, 178, 102) starty = self.y_start + (self.ym * 2 * (start.row)) - (self.ym * (1 if start.col & 1 else 0)) startx = (self.xm * 3 * (start.col)) + self.ym endRow = end.row endCol = end.col if (end.sector != start.sector): if end.sector.x < start.sector.x: endCol -= 32 if end.sector.x > start.sector.x: endCol += 32 if end.sector.y < start.sector.y: endRow -= 40 if end.sector.y > start.sector.y: endRow += 40 endy = self.y_start + (self.ym * 2 * (endRow)) - (self.ym * (1 if endCol & 1 else 0)) endx = (self.xm * 3 * endCol) + self.ym (startx, starty), (endx, endy) = self.clipping(startx, starty, endx, endy) else: endy = self.y_start + (self.ym * 2 * (endRow)) - (self.ym * (1 if endCol & 1 else 0)) endx = (self.xm * 3 * endCol) + self.ym lineStart = PDFCursor(startx, starty) lineEnd = PDFCursor(endx, endy) line = PDFLine(pdf.session, pdf.page, lineStart, lineEnd, stroke='solid', color=color, size=3) line._draw()
def _hline(self, pdf, width, colorname): hlineStart = PDFCursor(0, 0) hlineStart.x = 3 hlineStart.y = self.y_start - self.ym hlineStart.dx = self.xm * 3 hlineStart.dy = self.ym * 2 hlineEnd = PDFCursor(0, 0) hlineEnd.x = self.xm * 2.5 hlineEnd.y = self.y_start - self.ym hlineEnd.dx = self.xm * 3 hlineEnd.dy = self.ym * 2 color = pdf.get_color() color.set_color_by_name(colorname) hline = PDFLine(pdf.session, pdf.page, hlineStart, hlineEnd, stroke='solid', color=color, size=width) return (hlineStart, hlineEnd, hline)
def _rline(self, pdf, width, colorname): rlineStart = PDFCursor(0, 0) rlineStart.x = self.x_start + self.xm rlineStart.dx = self.xm * 3 rlineStart.dy = self.ym * 2 rlineEnd = PDFCursor(0, 0) rlineEnd.x = self.x_start rlineEnd.dx = self.xm * 3 rlineEnd.dy = self.ym * 2 color = pdf.get_color() color.set_color_by_name(colorname) rline = PDFLine(pdf.session, pdf.page, rlineStart, rlineEnd, stroke='solid', color=color, size=width) return (rlineStart, rlineEnd, rline)
def _lline(self, pdf, width, colorname): llineStart = PDFCursor(-10, 0) llineStart.x = self.x_start llineStart.dx = self.xm * 3 llineStart.dy = self.ym * 2 llineEnd = PDFCursor(-10, 0) llineEnd.x = self.x_start + self.xm llineEnd.dx = self.xm * 3 llineEnd.dy = self.ym * 2 color = pdf.get_color() color.set_color_by_name(colorname) lline = PDFLine(pdf.session, pdf.page, llineStart, llineEnd, stroke='solid', color=color, size=width) return (llineStart, llineEnd, lline)
def subsector_grid(self, pdf): color = pdf.get_color() color.set_color_by_name('lightgray') pdf.set_draw_color(color) vlineStart = PDFCursor(0, self.y_start + self.xm) vlineEnd = PDFCursor(0, self.y_start + self.xm + (180 * 4)) for x in xrange(self.x_start, 595, 144): vlineStart.x = x vlineEnd.x = x pdf.add_line(cursor1=vlineStart, cursor2=vlineEnd) hlineStart = PDFCursor(self.x_start, 0) hlineEnd = PDFCursor(591, 0) for y in xrange(self.y_start + self.xm, 780, 180): hlineStart.y = y hlineEnd.y = y pdf.add_line(cursor1=hlineStart, cursor2=hlineEnd)
def zone(self, pdf, star, point): point.x_plus(self.ym) point.y_plus(self.ym) color = pdf.get_color() if star.zone in ['R', 'F']: color.set_color_by_name('crimson') elif star.zone in ['A', 'U']: color.set_color_by_name('goldenrod') else: # no zone -> do nothing return radius = PDFCursor(self.xm, self.xm) circle = PDFEllipse(pdf.session, pdf.page, point, radius, color, size=2) circle._draw()
def cursor(self, x=0, y=0): return PDFCursor(x, y)
def place_system(self, pdf, star): def_font = pdf.get_font() pdf.set_font('times', size=4) col = (self.xm * 3 * (star.col)) if (star.col & 1): row = (self.y_start - self.ym * 2) + (star.row * self.ym * 2) else: row = (self.y_start - self.ym) + (star.row * self.ym * 2) point = PDFCursor(col, row) self.zone(pdf, star, point.copy()) width = self.string_width(pdf.get_font(), star.uwp) point.y_plus(7) point.x_plus(self.ym - (width / 2)) pdf.add_text(star.uwp.encode('ascii', 'replace'), point) if len(star.name) > 0: for chars in xrange(len(star.name), 0, -1): width = self.string_width(pdf.get_font(), star.name[:chars]) if width <= self.xm * 3.5: break point.y_plus(3.5) point.x = col point.x_plus(self.ym - (width / 2)) pdf.add_text(star.name[:chars].encode('ascii', 'replace'), point) added = star.alg if 'Cp' in star.tradeCode: added += '+' elif 'Cx' in star.tradeCode or 'Cs' in star.tradeCode: added += '*' else: added += ' ' added += '{:d}'.format(star.ggCount) point.y_plus(3.5) point.x = col width = pdf.get_font()._string_width(added) point.x_plus(self.ym - (width / 2)) pdf.add_text(added, point) added = '' tradeIn = StatCalculation.trade_to_btn(star.tradeIn) tradeThrough = StatCalculation.trade_to_btn(star.tradeIn + star.tradeOver) if self.routes == 'trade': added += "{:X}{:X}{:X}{:d}".format(star.wtn, tradeIn, tradeThrough, star.starportSize) elif self.routes == 'comm': added += "{}{} {}".format(star.baseCode, star.ggCount, star.importance) elif self.routes == 'xroute': added += " {}".format(star.importance) width = pdf.get_font()._string_width(added) point.y_plus(3.5) point.x = col point.x_plus(self.ym - (width / 2)) pdf.add_text(added, point) pdf.set_font(def_font)
def add_circle(self, pdf, center, radius, colorname): color = pdf.get_color() color.set_color_by_name(colorname) radius = PDFCursor(radius, radius) circle = PDFEllipse(pdf.session, pdf.page, center, radius, color, size=2) circle._draw()
def system(self, pdf, star): def_font = pdf.get_font() pdf.set_font('times', size=4) col = (self.xm * 3 * (star.col)) if (star.col & 1): row = (self.y_start - self.ym * 2) + (star.row * self.ym * 2) else: row = (self.y_start - self.ym) + (star.row * self.ym * 2) point = PDFCursor(col, row) self.zone(pdf, star, point.copy()) width = self.string_width(pdf.get_font(), star.uwp) point.y_plus(7) point.x_plus(self.ym - (width / 2)) pdf.add_text(star.uwp.encode('ascii', 'replace'), point) if len(star.name) > 0: for chars in xrange(len(star.name), 0, -1): width = self.string_width(pdf.get_font(), star.name[:chars]) if width <= self.xm * 3.5: break point.y_plus(3.5) point.x = col point.x_plus(self.ym - (width / 2)) pdf.add_text(star.name[:chars].encode('ascii', 'replace'), point) added = star.alg if star.tradeCode.subsector_capital: added += '+' elif star.tradeCode.sector_capital or star.tradeCode.other_capital: added += '*' else: added += ' ' added += '{:d}'.format(star.ggCount) point.y_plus(3.5) point.x = col width = pdf.get_font()._string_width(added) point.x_plus(self.ym - (width / 2)) pdf.add_text(added, point) added = '' tradeIn = StatCalculation.trade_to_btn(star.tradeIn) tradeThrough = StatCalculation.trade_to_btn(star.tradeIn + star.tradeOver) if self.routes == 'trade': added += "{:X}{:X}{:X}{:d}".format(star.wtn, tradeIn, tradeThrough, star.starportSize) elif self.routes == 'comm': added += "{}{} {}".format(star.baseCode, star.ggCount, star.importance) elif self.routes == 'xroute': added += " {}".format(star.importance) width = pdf.get_font()._string_width(added) point.y_plus(3.5) point.x = col point.x_plus(self.ym - (width / 2)) pdf.add_text(added, point) pdf.set_font(def_font)
def trade_line(self, pdf, edge, data): tradeColors = [ (255, 0, 0), # Red (224, 224, 16), # yellow - darker (0, 255, 0), # green (0, 255, 255), # Cyan (96, 96, 255), # blue - lighter (128, 0, 128), # purple (148, 0, 211), # violet ] start = edge[0] end = edge[1] trade = StatCalculation.trade_to_btn(data['trade']) - self.min_btn if trade < 0: return if trade > 6: logging.getLogger('PyRoute.HexMap').warn( "trade calculated over %d" % self.min_btn + 6) trade = 6 tradeColor = tradeColors[trade] color = pdf.get_color() color.set_color_by_number(tradeColor[0], tradeColor[1], tradeColor[2]) starty = self.y_start + (self.ym * 2 * (start.row)) - (self.ym * (1 if start.col & 1 else 0)) startx = (self.xm * 3 * (start.col)) + self.ym endRow = end.row endCol = end.col endCircle = True if (end.sector != start.sector): endCircle = False if end.sector.x < start.sector.x: endCol -= 32 if end.sector.x > start.sector.x: endCol += 32 if end.sector.y < start.sector.y: endRow -= 40 if end.sector.y > start.sector.y: endRow += 40 endy = self.y_start + (self.ym * 2 * (endRow)) - (self.ym * (1 if endCol & 1 else 0)) endx = (self.xm * 3 * endCol) + self.ym (startx, starty), (endx, endy) = self.clipping(startx, starty, endx, endy) else: endy = self.y_start + (self.ym * 2 * (endRow)) - (self.ym * (1 if endCol & 1 else 0)) endx = (self.xm * 3 * endCol) + self.ym lineStart = PDFCursor(startx, starty) lineEnd = PDFCursor(endx, endy) line = PDFLine(pdf.session, pdf.page, lineStart, lineEnd, stroke='solid', color=color, size=1) line._draw() radius = PDFCursor(2, 2) circle = PDFEllipse(pdf.session, pdf.page, lineStart, radius, color, size=3) circle._draw() if endCircle: circle = PDFEllipse(pdf.session, pdf.page, lineEnd, radius, color, size=3) circle._draw()
def __init__(self, galaxy, routes): super(PDFSectorMap, self).__init__(galaxy, routes) self.lineStart = PDFCursor(0, 0) self.lineEnd = PDFCursor(0, 0)