Example #1
0
oop CGContextConvertRectToDeviceSpace_wrap(CGContextRef c, float xin, float y, float w, float h) {
  CGRect x = CGContextConvertRectToDeviceSpace(c, CGRectMake(xin, y, w, h));
  objVectorOop r = Memory->objVectorObj->cloneSize(4);
  r->obj_at_put(0, as_floatOop(x.origin.x), false);
  r->obj_at_put(1, as_floatOop(x.origin.y), false);
  r->obj_at_put(2, as_floatOop(x.size.width), false);
  r->obj_at_put(3, as_floatOop(x.size.height), false);
  return r;
}
Example #2
0
//-----------------------------------------------------------------------------
CGRect CGDrawContext::pixelAlligned (const CGRect& r) const
{
    CGRect result = CGContextConvertRectToDeviceSpace (cgContext, r);
    result.origin.x = std::round (result.origin.x);
    result.origin.y = std::round (result.origin.y);
    result.size.width = std::round (result.size.width);
    result.size.height = std::round (result.size.height);
    result = CGContextConvertRectToUserSpace (cgContext, result);
    return result;
}
Example #3
0
//-----------------------------------------------------------------------------
CGDrawContext::CGDrawContext (CGContextRef cgContext, const CRect& rect)
    : COffscreenContext (rect)
    , cgContext (cgContext)
    , scaleFactor (1.)
{
    CFRetain (cgContext);

    // Get the scale for the context to check if it is for a Retina display
    CGRect userRect = CGRectMake (0, 0, 100, 100);
    CGRect deviceRect = CGContextConvertRectToDeviceSpace (cgContext, userRect);
    scaleFactor = deviceRect.size.height / userRect.size.height;

    init ();
}
Example #4
0
wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window )
   : wxGCDCImpl( owner )
{
    m_window = window;

    m_ok = true ;

    m_window->GetSize( &m_width , &m_height);
    if ( !m_window->IsShownOnScreen() )
        m_width = m_height = 0;

    CGContextRef cg = (CGContextRef) window->MacGetCGContextRef();

    m_release = false;
    if ( cg == NULL )
    {
        SetGraphicsContext( wxGraphicsContext::Create( window ) ) ;
        m_contentScaleFactor = window->GetContentScaleFactor();
        SetDeviceOrigin(-window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize());
    }
    else
    {
        // determine content scale
        CGRect userrect = CGRectMake(0, 0, 10, 10);
        CGRect devicerect;
        devicerect = CGContextConvertRectToDeviceSpace(cg, userrect);
        m_contentScaleFactor = devicerect.size.height / userrect.size.height;

        CGContextSaveGState( cg );
        m_release = true ;
        // make sure the context is having its origin at the wx-window coordinates of the
        // view (read at the top of window.cpp about the differences)
        if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 )
            CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );

        wxGraphicsContext* context = wxGraphicsContext::CreateFromNative( cg );
        context->EnableOffset(true);
        SetGraphicsContext( context );
    }
    DoSetClippingRegion( 0 , 0 , m_width , m_height ) ;

    SetBackground(wxBrush(window->GetBackgroundColour(),wxBRUSHSTYLE_SOLID));

    SetFont( window->GetFont() ) ;
}
static CGRect alignRectToUserSpace(CGContextRef context, CGRect r)
{
    // Compute the coordinates of the rectangle in device space.
    r = CGContextConvertRectToDeviceSpace(context, r);
    // Ensure that the x and y coordinates are at a pixel corner.
    r.origin.x = floor(r.origin.x);
    r.origin.y = floor(r.origin.y);
    // Ensure that the width and height are an integer number of
    // device pixels. Note that this produces a width and height
    // that is less than or equal to the original width. Another
    // approach is to use ceil to ensure that the new rectangle
    // encloses the original one.
    r.size.width = floor(r.size.width);
    r.size.height = floor(r.size.height);
    
    // Convert back to user space.
    return CGContextConvertRectToUserSpace(context, r);
}
FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int						 nChars,
        const FXTEXT_CHARPOS *	 pCharPos,
        CFX_Font *				 pFont,
        CFX_FontCache *			 pCache,
        const CFX_AffineMatrix * pObject2Device,
        FX_FLOAT				 font_size,
        FX_DWORD				 argb,
        int alpha_flag, void* pIccTransform)
{
    if (!pFont) {
        return FALSE;
    }
    FX_BOOL bBold = pFont->IsBold();
    if (!bBold && pFont->GetSubstFont() &&
            pFont->GetSubstFont()->m_Weight >= 500 &&
            pFont->GetSubstFont()->m_Weight <= 600) {
        return FALSE;
    }
    for (int i = 0; i < nChars; i ++) {
        if (pCharPos[i].m_bGlyphAdjust) {
            return FALSE;
        }
    }
    CGContextRef ctx = CGContextRef(m_pPlatformGraphics);
    if (NULL == ctx) {
        return FALSE;
    }
    CGContextSaveGState(ctx);
    CGContextSetTextDrawingMode(ctx, kCGTextFillClip);
    CGRect rect_cg;
    CGImageRef pImageCG = NULL;
    if (m_pClipRgn) {
        rect_cg = CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height());
        const CFX_DIBitmap*	pClipMask = m_pClipRgn->GetMask();
        if (pClipMask) {
            CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData(NULL,
                    pClipMask->GetBuffer(),
                    pClipMask->GetPitch() * pClipMask->GetHeight(),
                    _DoNothing);
            CGFloat decode_f[2] = {255.f, 0.f};
            pImageCG = CGImageMaskCreate(pClipMask->GetWidth(), pClipMask->GetHeight(),
                                         8, 8, pClipMask->GetPitch(), pClipMaskDataProvider,
                                         decode_f, FALSE);
            CGDataProviderRelease(pClipMaskDataProvider);
        }
    } else {
        rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
    }
    rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg);
    if (pImageCG) {
        CGContextClipToMask(ctx, rect_cg, pImageCG);
    } else {
        CGContextClipToRect(ctx, rect_cg);
    }
    FX_BOOL ret = _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2Device, font_size, argb, alpha_flag, pIccTransform);
    if (pImageCG) {
        CGImageRelease(pImageCG);
    }
    CGContextRestoreGState(ctx);
    return ret;
}