StyledStringStamp = function(canvas, rect, styledString, paint, halign, valign)
    if (styledString) then
        halign = halign or 0
        valign = valign or 0
        local stringRect = styledString:measure()
        canvas:setPaint(paint)
            :drawText(styledString,
                rect.left + halign * (rect:width() - stringRect:width()) - stringRect:minx(),
                rect.bottom + valign * (rect:height() - stringRect:height()) - stringRect:miny())
    end
end

return StyledStringStamp
