parameters: (self, dc)
docstring: Scale the DC
          
          This routine scales the DC based on the font size, determines the
          number of lines on a page, and saves some useful pixel locations like
          the top left corner and the width and height of the drawing area in
          logical coordinates.
docstring_summary: Scale the DC
          
          This routine scales the DC based on the font size, determines the
          number of lines on a page, and saves some useful pixel locations like
          the top left corner and the width and height of the drawing area in
          logical coordinates.
docstring_tokens: Scale the DC This routine scales the DC based on the font size determines the number of lines on a page and saves some useful pixel locations like the top left corner and the width and height of the drawing area in logical coordinates .
function: def _calculateScale(self, dc):
          """Scale the DC
          
          This routine scales the DC based on the font size, determines the
          number of lines on a page, and saves some useful pixel locations like
          the top left corner and the width and height of the drawing area in
          logical coordinates.
          """
          if self.debuglevel > 0:
              print
          
          dc.SetFont(self.stc.GetFont())
          
          # Calculate pixels per inch of the various devices.  The dc_ppi will be
          # equivalent to the page or screen PPI if the target is the printer or
          # a print preview, respectively.
          page_ppi_x, page_ppi_y = self.GetPPIPrinter()
          screen_ppi_x, screen_ppi_y = self.GetPPIScreen()
          dc_ppi_x, dc_ppi_y = dc.GetPPI()
          if self.debuglevel > 0:
              print("printer ppi: %dx%d" % (page_ppi_x, page_ppi_y))
              print("screen ppi: %dx%d" % (screen_ppi_x, screen_ppi_y))
              print("dc ppi: %dx%d" % (dc_ppi_x, dc_ppi_y))
          
          # Calculate paper size.  Note that this is the size in pixels of the
          # entire paper, which may be larger than the printable range of the
          # printer.  We need to use the entire paper size because we calculate
          # margins ourselves.  Note that GetPageSizePixels returns the
          # dimensions of the printable area.
          px, py, pw, ph = self.GetPaperRectPixels()
          page_width_inch = float(pw) / page_ppi_x
          page_height_inch = float(ph) / page_ppi_y
          if self.debuglevel > 0:
              print("page pixels: %dx%d" % (pw, ph))
              print("page size: %fx%f in" % (page_width_inch, page_height_inch))
          
          dw, dh = dc.GetSizeTuple()
          dc_pixels_per_inch_x = float(dw) / page_width_inch
          dc_pixels_per_inch_y = float(dh) / page_height_inch
          if self.debuglevel > 0:
              print("device pixels: %dx%d" % (dw, dh))
              print("device pixels per inch: %fx%f" % (dc_pixels_per_inch_x, dc_pixels_per_inch_y))
          
          # Calculate usable page size
          page_height_mm = page_height_inch * 25.4
          margin_mm = self.top_left_margin[1] + self.bottom_right_margin[1]
          usable_page_height_mm = page_height_mm - margin_mm
          
          # Lines per page is then the number of lines (based on the point size
          # reported by wx) that will fit into the usable page height
          self.lines_pp = self._calculateLinesPerPage(dc, usable_page_height_mm)
          
          # The final DC scale factor is then the ratio of the total height in
          # pixels inside the margins to the number of pixels that it takes to
          # represent the number of lines
          dc_margin_pixels = float(dc_pixels_per_inch_y) * margin_mm / 25.4
          dc_usable_pixels = dh - dc_margin_pixels
          page_to_dc = self._calculateScaleFactor(dc, dc_usable_pixels, self.lines_pp)
  
          dc.SetUserScale(page_to_dc, page_to_dc)
  
          if self.debuglevel > 0:
              print("Usable page height: %f in" % (usable_page_height_mm / 25.4))
              print("Usable page pixels: %d" % dc_usable_pixels)
              print("lines per page: %d" % self.lines_pp)
              print("page_to_dc: %f" % page_to_dc)
  
          self.x1 = dc.DeviceToLogicalXRel(float(self.top_left_margin[0]) / 25.4 * dc_pixels_per_inch_x)
          self.y1 = dc.DeviceToLogicalXRel(float(self.top_left_margin[1]) / 25.4 * dc_pixels_per_inch_y)
          self.x2 = dc.DeviceToLogicalXRel(dw) - dc.DeviceToLogicalXRel(float(self.bottom_right_margin[0]) / 25.4 * dc_pixels_per_inch_x)
          self.y2 = dc.DeviceToLogicalYRel(dh) - dc.DeviceToLogicalXRel(float(self.bottom_right_margin[1]) / 25.4 * dc_pixels_per_inch_y)
          page_height = self.y2 - self.y1
  
          #self.lines_pp = int(page_height / dc_pixels_per_line)
          
          if self.debuglevel > 0:
              print("page size: %d,%d -> %d,%d, height=%d" % (int(self.x1), int(self.y1), int(self.x2), int(self.y2), page_height))
function_tokens: def _calculateScale ( self , dc ) : if self . debuglevel > 0 : print dc . SetFont ( self . stc . GetFont ( ) ) # Calculate pixels per inch of the various devices.  The dc_ppi will be # equivalent to the page or screen PPI if the target is the printer or # a print preview, respectively. page_ppi_x , page_ppi_y = self . GetPPIPrinter ( ) screen_ppi_x , screen_ppi_y = self . GetPPIScreen ( ) dc_ppi_x , dc_ppi_y = dc . GetPPI ( ) if self . debuglevel > 0 : print ( "printer ppi: %dx%d" % ( page_ppi_x , page_ppi_y ) ) print ( "screen ppi: %dx%d" % ( screen_ppi_x , screen_ppi_y ) ) print ( "dc ppi: %dx%d" % ( dc_ppi_x , dc_ppi_y ) ) # Calculate paper size.  Note that this is the size in pixels of the # entire paper, which may be larger than the printable range of the # printer.  We need to use the entire paper size because we calculate # margins ourselves.  Note that GetPageSizePixels returns the # dimensions of the printable area. px , py , pw , ph = self . GetPaperRectPixels ( ) page_width_inch = float ( pw ) / page_ppi_x page_height_inch = float ( ph ) / page_ppi_y if self . debuglevel > 0 : print ( "page pixels: %dx%d" % ( pw , ph ) ) print ( "page size: %fx%f in" % ( page_width_inch , page_height_inch ) ) dw , dh = dc . GetSizeTuple ( ) dc_pixels_per_inch_x = float ( dw ) / page_width_inch dc_pixels_per_inch_y = float ( dh ) / page_height_inch if self . debuglevel > 0 : print ( "device pixels: %dx%d" % ( dw , dh ) ) print ( "device pixels per inch: %fx%f" % ( dc_pixels_per_inch_x , dc_pixels_per_inch_y ) ) # Calculate usable page size page_height_mm = page_height_inch * 25.4 margin_mm = self . top_left_margin [ 1 ] + self . bottom_right_margin [ 1 ] usable_page_height_mm = page_height_mm - margin_mm # Lines per page is then the number of lines (based on the point size # reported by wx) that will fit into the usable page height self . lines_pp = self . _calculateLinesPerPage ( dc , usable_page_height_mm ) # The final DC scale factor is then the ratio of the total height in # pixels inside the margins to the number of pixels that it takes to # represent the number of lines dc_margin_pixels = float ( dc_pixels_per_inch_y ) * margin_mm / 25.4 dc_usable_pixels = dh - dc_margin_pixels page_to_dc = self . _calculateScaleFactor ( dc , dc_usable_pixels , self . lines_pp ) dc . SetUserScale ( page_to_dc , page_to_dc ) if self . debuglevel > 0 : print ( "Usable page height: %f in" % ( usable_page_height_mm / 25.4 ) ) print ( "Usable page pixels: %d" % dc_usable_pixels ) print ( "lines per page: %d" % self . lines_pp ) print ( "page_to_dc: %f" % page_to_dc ) self . x1 = dc . DeviceToLogicalXRel ( float ( self . top_left_margin [ 0 ] ) / 25.4 * dc_pixels_per_inch_x ) self . y1 = dc . DeviceToLogicalXRel ( float ( self . top_left_margin [ 1 ] ) / 25.4 * dc_pixels_per_inch_y ) self . x2 = dc . DeviceToLogicalXRel ( dw ) - dc . DeviceToLogicalXRel ( float ( self . bottom_right_margin [ 0 ] ) / 25.4 * dc_pixels_per_inch_x ) self . y2 = dc . DeviceToLogicalYRel ( dh ) - dc . DeviceToLogicalXRel ( float ( self . bottom_right_margin [ 1 ] ) / 25.4 * dc_pixels_per_inch_y ) page_height = self . y2 - self . y1 #self.lines_pp = int(page_height / dc_pixels_per_line) if self . debuglevel > 0 : print ( "page size: %d,%d -> %d,%d, height=%d" % ( int ( self . x1 ) , int ( self . y1 ) , int ( self . x2 ) , int ( self . y2 ) , page_height ) )