MCPcopy Create free account
hub / github.com/PageBot/PageBot / em

Function em

Lib/pagebot/toolbox/units.py:1869–1913  ·  view source on GitHub ↗

Create an Em instance. >>> u = em(1, base=32) >>> u.pt 32 >>> u.base = pt(34) >>> u.pt 34 >>> u = em(1.5, base=48) >>> u 1.5em >>> u.pt == 48*1.5 True

(v, *args, **kwargs)

Source from the content-addressed store, hash-verified

1867# Em
1868
1869def em(v, *args, **kwargs):
1870 """Create an Em instance.
1871
1872 >>> u = em(1, base=32)
1873 >>> u.pt
1874 32
1875 >>> u.base = pt(34)
1876 >>> u.pt
1877 34
1878 >>> u = em(1.5, base=48)
1879 >>> u
1880 1.5em
1881 >>> u.pt == 48*1.5
1882 True
1883
1884 """
1885 u = None
1886 base = kwargs.get('base', EM_FONT_SIZE)
1887 # Default not used by Em.
1888 g = kwargs.get('g', 0)
1889
1890 # If there are more arguments, bind them together in a list.
1891 if args:
1892 v = [v]+list(args)
1893 if isinstance(v, (tuple, list)):
1894 u = []
1895
1896 # Recursively append.
1897 for uv in v:
1898 u.append(em(uv, base=base, g=g))
1899 u = tuple(u)
1900 elif isinstance(v, (int, float, RelativeUnit)):
1901 u = Em(v, base=base, g=g)
1902 elif isinstance(v, str):
1903 v = v.strip().lower()
1904 if v.endswith(Em.UNIT):
1905 v = asNumberOrNone(v[:-2])
1906 if v is not None:
1907 u = Em(v, base=base, g=g)
1908 # Something else, recursively try again.
1909 else:
1910 u = units(v, base=base, g=g)
1911 # Only makes sense for relative if the same.
1912 assert isinstance(u, Em)
1913 return u
1914
1915class Em(RelativeUnit):
1916 """Em size is based on the current setting of the fontSize. Used in CSS

Callers 11

getRootStyleFunction · 0.90
constants.pyFile · 0.90
stylelib.pyFile · 0.90
TypesetterClass · 0.90
fromBabelStringMethod · 0.90
getFSStyleMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
FontIconClass · 0.90
__init__Method · 0.90
FontIconClass · 0.90

Calls 5

asNumberOrNoneFunction · 0.90
EmClass · 0.85
unitsFunction · 0.85
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected