Exemplo n.º 1
0
def drawWatermarkText(writeContext, line, xOffset, yOffset, angle, scale,
                      opacity):
    if line:
        rect = CTLineGetImageBounds(line, writeContext)
        imageWidth = rect.size.width
        imageHeight = rect.size.height

        Quartz.CGContextSaveGState(writeContext)
        Quartz.CGContextSetAlpha(writeContext, opacity)
        Quartz.CGContextTranslateCTM(writeContext, xOffset, yOffset)
        Quartz.CGContextTranslateCTM(writeContext, imageWidth / 2,
                                     imageHeight / 2)
        Quartz.CGContextRotateCTM(writeContext, angle * math.pi / 180)
        Quartz.CGContextTranslateCTM(writeContext, -imageWidth / 2,
                                     -imageHeight / 2)
        Quartz.CGContextScaleCTM(writeContext, scale, scale)
        Quartz.CGContextSetTextPosition(writeContext, 0.0, 0.0)
        CTLineDraw(line, writeContext)
        Quartz.CGContextRestoreGState(writeContext)
Exemplo n.º 2
0
def drawWatermarkText(ctx, line, xOffset, yOffset, angle, scale, opacity):
    #   CGContextRef ctx
    #   CTLineRef line
    #   float xOffset, yOffset, angle ([degree]), scale, opacity ([0.0, 1.0])
    if line:
        rect = CTLineGetImageBounds(line, ctx)
        imageWidth = rect.size.width
        imageHeight = rect.size.height

        CG.CGContextSaveGState(ctx)
        CG.CGContextSetAlpha(ctx, opacity)
        CG.CGContextTranslateCTM(ctx, xOffset, yOffset)
        CG.CGContextScaleCTM(ctx, scale, scale)
        CG.CGContextTranslateCTM(ctx, imageWidth / 2, imageHeight / 2)
        CG.CGContextRotateCTM(ctx, angle * math.pi / 180)
        CG.CGContextTranslateCTM(ctx, -imageWidth / 2, -imageHeight / 2)
        CG.CGContextSetTextPosition(ctx, 0.0, 0.0)
        CTLineDraw(line, ctx)
        CG.CGContextRestoreGState(ctx)