Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

Commit

Permalink
Merge pull request #19 from beeware/system-font-size
Browse files Browse the repository at this point in the history
Add support for system-size font definitions.
  • Loading branch information
freakboy3742 authored May 25, 2020
2 parents cecbca9 + 8495b5f commit 8681cc7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions changes/19.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for delaring a system default font size.
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ long_description_content_type = text/x-rst
[options]
python_requires = >= 3.5
packages = find:
package_dir =
= src

[options.packages.find]
include =
travertino
where = src

[flake8]
exclude=
Expand All @@ -55,5 +56,5 @@ ignore = E133,E226,W503
combine_as_imports = true
include_trailing_comma = true
line_length = 79
multi_line_output = 5
multi_line_output = 3
not_skip = __init__.py
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions travertino/constants.py → src/travertino/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@

FONT_WEIGHTS = {BOLD}

######################################################################
# Font Size
######################################################################

SYSTEM_DEFAULT_FONT_SIZE = -1

######################################################################
# Colors
######################################################################
Expand Down
File renamed without changes.
15 changes: 11 additions & 4 deletions travertino/fonts.py → src/travertino/fonts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from .constants import (
NORMAL, FONT_STYLES, FONT_VARIANTS, FONT_WEIGHTS,
ITALIC, OBLIQUE, SMALL_CAPS, BOLD
BOLD,
FONT_STYLES,
FONT_VARIANTS,
FONT_WEIGHTS,
ITALIC,
NORMAL,
OBLIQUE,
SMALL_CAPS,
SYSTEM_DEFAULT_FONT_SIZE,
)


Expand Down Expand Up @@ -29,11 +36,11 @@ def __hash__(self):
return hash(('FONT', self.family, self.size, self.style, self.variant, self.weight))

def __repr__(self):
return '<Font: {}{}{}{}pt {}>'.format(
return '<Font: {}{}{}{} {}>'.format(
'' if self.style is NORMAL else (self.style + ' '),
'' if self.variant is NORMAL else (self.variant + ' '),
'' if self.weight is NORMAL else (self.weight + ' '),
self.size,
'system default size' if self.size == SYSTEM_DEFAULT_FONT_SIZE else '{}pt'.format(self.size),
self.family
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 20 additions & 2 deletions tests/test_font.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from unittest import TestCase

from travertino.constants import NORMAL, ITALIC, OBLIQUE, SMALL_CAPS, BOLD
from travertino.fonts import font, Font
from travertino.constants import (
BOLD,
ITALIC,
NORMAL,
OBLIQUE,
SMALL_CAPS,
SYSTEM_DEFAULT_FONT_SIZE,
)
from travertino.fonts import Font, font


class FontTests(TestCase):
Expand Down Expand Up @@ -65,6 +72,17 @@ def test_repr(self):
'<Font: italic bold 12pt Comic Sans>'
)

# Check system default size handling
self.assertEqual(
repr(Font('Comic Sans', SYSTEM_DEFAULT_FONT_SIZE)),
'<Font: system default size Comic Sans>'
)

self.assertEqual(
repr(Font('Comic Sans', SYSTEM_DEFAULT_FONT_SIZE, style=ITALIC)),
'<Font: italic system default size Comic Sans>'
)

def test_simple_construction(self):
# Simplest case
self.assertFont(
Expand Down

0 comments on commit 8681cc7

Please sign in to comment.