class for drawing and saving simple Windows bitmap files
| 144 | Color.GRAY = Color( 128, 128, 128 ) |
| 145 | |
| 146 | class BitMap(object): |
| 147 | """class for drawing and saving simple Windows bitmap files""" |
| 148 | |
| 149 | LINE_SOLID = 0 |
| 150 | LINE_DASHED = 1 |
| 151 | LINE_DOTTED = 2 |
| 152 | LINE_DOT_DASH=3 |
| 153 | _DASH_LEN = 12.0 |
| 154 | _DOT_LEN = 6.0 |
| 155 | _DOT_DASH_LEN = _DOT_LEN + _DASH_LEN |
| 156 | |
| 157 | def __init__( self, width, height, |
| 158 | bkgd = Color.WHITE, frgd = Color.BLACK ): |
| 159 | self.wd = int( ceil(width) ) |
| 160 | self.ht = int( ceil(height) ) |
| 161 | self.bgcolor = 0 |
| 162 | self.fgcolor = 1 |
| 163 | self.palette = [] |
| 164 | self.palette.append( bkgd.toLong() ) |
| 165 | self.palette.append( frgd.toLong() ) |
| 166 | self.setDefaultPenColor() |
| 167 | |
| 168 | tmparray = [ self.bgcolor ] * self.wd |
| 169 | self.bitarray = [ tmparray[:] for i in range( self.ht ) ] |
| 170 | self.currentPen = 1 |
| 171 | self.fontName = "%s-%d-%s" % ( "none", 0, "none" ) |
| 172 | |
| 173 | def setDefaultPenColor( self ): |
| 174 | self.currentPen = self.fgcolor |
| 175 | |
| 176 | def setPenColor( self, pcolor ): |
| 177 | oldColor = self.currentPen |
| 178 | # look for c in palette |
| 179 | pcolornum = pcolor.toLong() |
| 180 | try: |
| 181 | self.currentPen = self.palette.index( pcolornum ) |
| 182 | except ValueError: |
| 183 | if len( self.palette ) < 256 : |
| 184 | self.palette.append( pcolornum ) |
| 185 | self.currentPen = len( self.palette ) - 1 |
| 186 | else: |
| 187 | self.currentPen = self.fgcolor |
| 188 | |
| 189 | return Color.fromLong( self.palette[oldColor] ) |
| 190 | |
| 191 | def getPenColor( self ): |
| 192 | return Color.fromLong( self.palette[self.currentPen] ) |
| 193 | |
| 194 | def plotPoint( self, x, y ): |
| 195 | if ( 0 <= x < self.wd and 0 <= y < self.ht ): |
| 196 | x = int(x) |
| 197 | y = int(y) |
| 198 | self.bitarray[y][x] = self.currentPen |
| 199 | |
| 200 | def drawRect( self, x, y, wid, ht, fill=False ): |
| 201 | x = int(x) |
| 202 | y = int(y) |
| 203 | cury = y |