""" weasyprint.tests.test_draw.test_box ----------------------------------- Test how boxes, borders, outlines are drawn. :copyright: Copyright 2011-2019 Simon Sapin and contributors, see AUTHORS. :license: BSD, see LICENSE for details. """ import itertools from ... import HTML from ..testing_utils import assert_no_logs from . import PIXELS_BY_CHAR, assert_different_renderings, assert_pixels @assert_no_logs def test_borders(margin='10px', prop='border'): """Test the rendering of borders""" source = '''
''' # Do not test the exact rendering of earch border style but at least # check that they do not do the same. assert_different_renderings(140, 110, [ ('%s_%s' % (prop, border_style), source % (margin, prop, border_style)) for border_style in [ 'none', 'solid', 'dashed', 'dotted', 'double', 'inset', 'outset', 'groove', 'ridge']]) css_margin = margin width = 140 height = 110 margin = 10 border = 10 solid_pixels = [[PIXELS_BY_CHAR['_']] * width for y in range(height)] for x in range(margin, width - margin): for y in itertools.chain( range(margin, margin + border), range(height - margin - border, height - margin)): solid_pixels[y][x] = PIXELS_BY_CHAR['B'] for y in range(margin, height - margin): for x in itertools.chain( range(margin, margin + border), range(width - margin - border, width - margin)): solid_pixels[y][x] = PIXELS_BY_CHAR['B'] solid_pixels = [b''.join(line) for line in solid_pixels] assert_pixels( prop + '_solid', 140, 110, solid_pixels, source % (css_margin, prop, 'solid')) @assert_no_logs def test_outlines(): return test_borders(margin='20px', prop='outline') @assert_no_logs def test_small_borders_1(): # Regression test for ZeroDivisionError on dashed or dotted borders # smaller than a dash/dot. # https://github.com/Kozea/WeasyPrint/issues/49 html = ''' ''' for style in ['none', 'solid', 'dashed', 'dotted']: HTML(string=html % style).write_image_surface() @assert_no_logs def test_small_borders_2(): # Regression test for ZeroDivisionError on dashed or dotted borders # smaller than a dash/dot. # https://github.com/Kozea/WeasyPrint/issues/146 html = ''' ''' for style in ['none', 'solid', 'dashed', 'dotted']: HTML(string=html % style).write_image_surface() @assert_no_logs def test_margin_boxes(): assert_pixels('margin_boxes', 15, 15, ''' _______________ _GGG______BBBB_ _GGG______BBBB_ _______________ _____RRRR______ _____RRRR______ _____RRRR______ _____RRRR______ _______________ _bbb______gggg_ _bbb______gggg_ _bbb______gggg_ _bbb______gggg_ _bbb______gggg_ _______________ ''', ''' ''')