def drawWatermarkText(writeContext, line, xOffset, yOffset, angle, 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.CGContextRotateCTM(writeContext, angle * math.pi / 180) Quartz.CGContextSetTextPosition(writeContext, 0.0, 0.0) CTLineDraw(line, writeContext) Quartz.CGContextRestoreGState(writeContext)
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)
def _get_imageBounds(self): """Property that answers the bounding box (actual black shape) of the text line.""" (xpt, ypt), (wpt, hpt) = CTLineGetImageBounds(self._ctLine, None) return pt(xpt, ypt, wpt, hpt)