예제 #1
0
    def CreateButtons( me):
        me.SetSize( (400, 40) )
        sizer = wx.BoxSizer( wx.HORIZONTAL)

        navButtonSize = wx.Size(40, wx.DefaultSize.y)

        buttons_description = [
            ( wx.ID_PREVIEW_CLOSE     , _('&Отказ')      , wx.DefaultSize , wx.ALIGN_CENTRE | wx.ALL ),
            ( wx.ID_PREVIEW_PRINT     , _('&Печат...')   , wx.DefaultSize , wx.ALIGN_CENTRE | wx.ALL ),
            ( wx.ID_PREVIEW_FIRST     , _('|<<')         , navButtonSize  , wx.ALIGN_CENTRE | wx.ALL ),
            ( wx.ID_PREVIEW_PREVIOUS  , _('<<')          , navButtonSize  , wx.ALIGN_CENTRE | wx.RIGHT | wx.TOP | wx.BOTTOM ),
            ( wx.ID_PREVIEW_NEXT      , _('>>')          , navButtonSize  , wx.ALIGN_CENTRE | wx.RIGHT | wx.TOP | wx.BOTTOM ),
            ( wx.ID_PREVIEW_LAST      , _('>>|')         , navButtonSize  , wx.ALIGN_CENTRE | wx.RIGHT | wx.TOP | wx.BOTTOM ),
            ( wx.ID_PREVIEW_GOTO      , _('&Страница...'), wx.DefaultSize , wx.ALIGN_CENTRE | wx.ALL ),
        ]

        for descr in buttons_description:
            btn = wx.Button( me, descr[0], descr[1], wx.DefaultPosition, descr[2], 0)
            sizer.Add( btn, 0, descr[ 3], 5)

        choices = [ str(i)+'%' for i in range(10, 101, 5) ]
        me.zoom = wx.Choice( me, wx.ID_PREVIEW_ZOOM,  choices=choices, style=0)
        sizer.Add( me.zoom, 0, wx.ALIGN_CENTRE | wx.ALL, 5 )
        me.zoom.SetStringSelection( '100%')
        #me.SetZoomControl( 100) #me.GetPrintPreview().GetZoom())

        me.SetSizer( sizer)
        sizer.Fit( me)
예제 #2
0
    def _draw_text( me, txt, x, y, angle =0, base_y =0):
        from svd_util.ui.wxtxt import _
        txt = _(txt)
        #print '@@@@ draw text', type(txt), repr(txt)
        import sys
        # XXX FIXME dont know why PrinterDC is not consistent for linux/win32
        special_mode = isinstance( me.context, wx.PrinterDC) and sys.platform == 'win32'

        if special_mode:
            dpi_pixels = me.context.GetPPI()
            dpi = [
                    me.context.DeviceToLogicalXRel( dpi_pixels[0]),
                    me.context.DeviceToLogicalYRel( dpi_pixels[1]),
                  ]
        else:
            dpi = me.context.GetPPI()

        if me.DEBUG:
            d = {
                wx.MM_TWIPS     : 'Each logical unit is 1/20 of a point, or 1/1440 of an inch.',
                wx.MM_POINTS    : 'Each logical unit is a point, or 1/72 of an inch.',
                wx.MM_METRIC    : 'Each logical unit is 1 mm.',
                wx.MM_LOMETRIC  : 'Each logical unit is 1/10 of a mm.',
                wx.MM_TEXT      : 'Each logical unit is 1 pixel.',
            }
            print 'mapmode:', d[ me.context.GetMapMode()], 'dpi:', dpi
            print me.context.LogicalToDeviceYRel(1000.0)

        me.PushState()
        matr = me.state.matrix
        matr.translate( x, y, pre=True)

        if angle:
            matr.rotate( angle, pre=True)

        dx, dy, descent, ext_leading = me.context.GetFullTextExtent( txt)
        #print 'fontmetrics', dx, dy, descent, ext_leading
        dy -= descent #get to the baseline
        #86: dpy[y]; xdpyinfo | grep resolution
        coef = 72.0/dpi[1] #0.75 ????  72/86 = 0.837
        #друга причина може да е _какво_ е 14пт - bbox.h или височината dy-descent?
        dx *= coef
        dy *= coef
        descent *= coef
        #print 'fontmetrics', dx, dy, descent, ext_leading

        scale = matr.transform_y_size( 1)
        if me.DEBUG:
            print 'scale' , scale
        #ext = scale * base_y
        if base_y:
            scale *= float( base_y) / dy
        else:
            base_y = dy

        font = me.context.GetFont()
        point_size = font.GetPointSize()
        scaled_point_size = point_size * scale * coef

        if 0: #'linux' in sys.platform:
            if 0:
                from reportlab.pdfbase.pdfmetrics import stringWidth
                font_data = me.state.font_data
                rl_width = stringWidth( txt, font_data.faceName, font_data.pointSize)
                wx_width = me.context.GetTextExtent( txt)[0]
                if not wx_width: wx_width = 1
                font_map_correction_coef = float(rl_width) / wx_width
            else:
                font_map_correction_coef = 0.8
            scaled_point_size *= font_map_correction_coef
        elif special_mode:
            # just to be sure it'll fit when we map different font from the one reportlab has used
            scaled_point_size *= 0.8
            fsize_pixels = font.GetPixelSize()
            fwidth, fheight = [
                me.context.DeviceToLogicalXRel( fsize_pixels[0]),
                me.context.DeviceToLogicalYRel( fsize_pixels[1])
            ]
            base_y += fheight
            if me.DEBUG:
                print 'In printer mode', base_y, 'h=', fheight, 'w=',fwidth, 'pix=', fsize_pixels

        font.SetPointSize( scaled_point_size)

        # XXX Why does not wx scale fonts when outputting to a pixel printer in windows ??
        # pixel_size = font.GetPixelSize()
        # font.SetPixelSize( pixel_size)
        me.context.SetFont( font)

        if me.DEBUG:
            print 'fontsize', point_size, 'scaled fontsize', scaled_point_size
            matrixbox = matr.copy()
            if 1*'fullbbox':
                dy += descent
                matrixbox.translate( 0, descent )
            pts = [ map( to_int, matrixbox.transform_xy( x, y))
                    for x,y in ((0,0), (dx,0), (dx,dy), (0,dy))
                  ]
            me.context.SetBrush( wx.Brush( wx.NamedColour('RED')))
            me.context.DrawPolygon( pts)

        p = me._transform_xy( 0, 0)
        q = me._transform_xy( dx, 0)
        from math import atan2, pi
        pangle = -180/pi * atan2( q[1]-p[1], q[0]-p[0])

        if 0:
            base_y = scaled_point_size - base_y + descent
        #print base_y
        #base_y -= 1 #??? закръглението требе да се обърне:-0.5 ЗА НЯКОИ неща ???
        matr.translate( 0, base_y, pre=True)

        p = me._transform_xy_int( 0,0)
        me.context.DrawRotatedText( txt, p[0], p[1], pangle)

        me.PopState()