Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add font properties handling #52

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6feae5a
Add font shorthand parser
goanpeca Jan 2, 2020
c7b7dc5
Add font properties to declaration
goanpeca Jan 2, 2020
e1f1401
Add tests for font parser and properties
goanpeca Jan 2, 2020
ba2cc2f
Fix codestyle
goanpeca Jan 2, 2020
32b9f47
Add font_family list property, fix code review comments
goanpeca Jan 2, 2020
f497c6f
Fix code style
goanpeca Jan 2, 2020
fc14114
Update list property and tests
goanpeca Jan 3, 2020
3fad53c
Fix code style
goanpeca Jan 3, 2020
c4cc7bb
Add initial support to search for fonts on mac with rubicon
goanpeca Jan 3, 2020
4f8c4b9
Update font for linux
goanpeca Jan 3, 2020
925bf17
Update tests
goanpeca Jan 3, 2020
bc376e5
Copy ahem font
goanpeca Jan 4, 2020
71eb789
Add win font query
goanpeca Jan 4, 2020
ba7de67
Refactor code, cache fonts and address code review comments
goanpeca Jan 8, 2020
d496261
Add fontdb and refactor code. Fix code style
goanpeca Jan 8, 2020
d755bc5
Update CI and add font copy initialization
goanpeca Jan 9, 2020
ed23e67
Test CI
goanpeca Jan 9, 2020
dfe6e61
Update font registry on windows
goanpeca Jan 9, 2020
8d063b9
Add more tests
goanpeca Jan 11, 2020
8e40d6d
Fix code style
goanpeca Jan 11, 2020
2fb5815
Fix tests
goanpeca Jan 11, 2020
be72024
Fix tests
goanpeca Jan 11, 2020
91b816d
More tests
goanpeca Jan 11, 2020
1e496c6
Remove print statements
goanpeca Jan 11, 2020
382e758
Update CI config and add exception message for incorrect font shortha…
goanpeca Jan 11, 2020
8b3b6f1
Add font shorthand wrapers and update tests
goanpeca Jan 16, 2020
e4cd59c
Fix code style
goanpeca Jan 16, 2020
dc1710f
Fix error on GTK test
goanpeca Jan 16, 2020
c2bd8cd
Break tests, add pytest-xdist, clean up code
goanpeca Jan 20, 2020
944e53f
Fix tests
goanpeca Jan 20, 2020
94cb398
Merge branch 'master' into enh/add-font-properties
goanpeca Jan 27, 2020
40faa93
Merge branch 'master' into enh/add-font-properties
goanpeca Jan 27, 2020
b754c81
Fix code style
goanpeca Jan 27, 2020
94329c9
Merge with master
goanpeca Apr 27, 2020
d824c86
Fix code style
goanpeca Apr 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 61 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
task: ['pycodestyle']
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.8
- name: Install dependencies
run: |
pip install --upgrade pip setuptools beefore
Expand All @@ -25,31 +25,35 @@ jobs:
beefore --username github-actions --repository ${{ github.repository }} --pull-request ${{ github.event.number }} --commit ${{ github.event.pull_request.head.sha }} ${{ matrix.task }} .

smoke:
name: Smoke test
goanpeca marked this conversation as resolved.
Show resolved Hide resolved
name: Smoke test (Linux) (3.5)
needs: beefore
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.5
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.5
- name: Install dependencies
run: |
pip install --upgrade pip setuptools pytest-tldr
sudo apt-get install -y python3-gi python3-gi-cairo gir1.2-gtk-3.0 python3-dev libgirepository1.0-dev libcairo2-dev pkg-config
pip install --upgrade pip setuptools pytest pytest-xdist pytest-tldr
pip install -e .
- name: Install fonts
run: |
xvfb-run -a -s '-screen 0 2048x1536x24' python tests/utils.py
- name: Test
run: |
python setup.py test
xvfb-run -a -s '-screen 0 2048x1536x24' pytest tests/ -n auto

python-versions:
name: Python compatibility test
name: Python compatibility test (Linux)
needs: smoke
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.5, 3.6]
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -58,8 +62,54 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip setuptools
sudo apt-get install -y python3-gi python3-gi-cairo gir1.2-gtk-3.0 python3-dev libgirepository1.0-dev libcairo2-dev pkg-config
pip install --upgrade pip setuptools pytest pytest-xdist pytest-tldr
pip install -e .
- name: Install fonts
run: |
xvfb-run -a -s '-screen 0 2048x1536x24' python tests/utils.py
- name: Test
run: |
xvfb-run -a -s '-screen 0 2048x1536x24' pytest tests/ -n auto

windows:
name: Windows tests
needs: python-versions
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.5
uses: actions/setup-python@v1
with:
python-version: 3.5
- name: Install dependencies
run: |
pip install --upgrade pip setuptools pytest pytest-xdist pytest-tldr
pip install -e .
- name: Install fonts
run: |
python tests/utils.py
- name: Test
run: |
pytest tests/ -n auto

macOS:
name: macOS tests
needs: python-versions
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.5
uses: actions/setup-python@v1
with:
python-version: 3.5
- name: Install dependencies
run: |
pip install --upgrade pip setuptools pytest pytest-xdist pytest-tldr
pip install -e .
- name: Install fonts
run: |
python tests/utils.py
- name: Test
run: |
python setup.py test
pytest tests/ -n auto
123 changes: 119 additions & 4 deletions colosseum/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .validators import (is_color, is_integer, is_length, is_number,
is_percentage, ValidationError)
from .exceptions import ValidationError
from .validators import is_color, is_font_family, is_integer, is_length, is_number, is_percentage
from .wrappers import FontFamily


class Choices:
Expand Down Expand Up @@ -36,13 +37,13 @@ def validate(self, value):
def __str__(self):
choices = set([str(c).lower().replace('_', '-') for c in self.constants])
for validator in self.validators:
choices.add(validator.description)
choices.update(validator.description.split(', '))

if self.explicit_defaulting_constants:
for item in self.explicit_defaulting_constants:
choices.add(item)

return ", ".join(sorted(choices))
return ", ".join(sorted(set(choices)))


######################################################################
Expand All @@ -51,6 +52,11 @@ def __str__(self):
HTML4 = 'html4'
HTML5 = 'html5'

######################################################################
# Other constants
######################################################################
EMPTY = '<empty>'

######################################################################
# Common constants
######################################################################
Expand Down Expand Up @@ -235,6 +241,8 @@ def __str__(self):
# 10.8 Leading and half-leading
######################################################################
# line_height
LINE_HEIGHT_CHOICES = Choices(NORMAL, validators=[is_number, is_length, is_percentage],
explicit_defaulting_constants=[INHERIT])
# vertical_align

######################################################################
Expand Down Expand Up @@ -317,26 +325,133 @@ def __str__(self):
######################################################################
# font_family

SERIF = 'serif'
SANS_SERIF = 'sans-serif'
CURSIVE = 'cursive'
FANTASY = 'fantasy'
MONOSPACE = 'monospace'

GENERIC_FAMILY_FONTS = [SERIF, SANS_SERIF, CURSIVE, FANTASY, MONOSPACE]

FONT_FAMILY_CHOICES = Choices(
validators=[is_font_family],
explicit_defaulting_constants=[INHERIT, INITIAL],
)

######################################################################
# 15.4 Font Styling
######################################################################
# font_style
NORMAL = 'normal'
ITALIC = 'italic'
OBLIQUE = 'oblique'

FONT_STYLE_CHOICES = Choices(
NORMAL,
ITALIC,
OBLIQUE,
explicit_defaulting_constants=[INHERIT],
)

######################################################################
# 15.5 Small-caps
######################################################################
# font_variant
SMALL_CAPS = 'small-caps'
FONT_VARIANT_CHOICES = Choices(
NORMAL,
SMALL_CAPS,
explicit_defaulting_constants=[INHERIT],
)

######################################################################
# 15.6 Font boldness
######################################################################
# font_weight
BOLD = 'bold'
BOLDER = 'bolder'
LIGHTER = 'lighter'
WEIGHT_100 = '100'
WEIGHT_200 = '200'
WEIGHT_300 = '300'
WEIGHT_400 = '400'
WEIGHT_500 = '500'
WEIGHT_600 = '600'
WEIGHT_700 = '700'
WEIGHT_800 = '800'
WEIGHT_900 = '900'

FONT_WEIGHT_CHOICES = Choices(
NORMAL,
BOLD,
BOLDER,
LIGHTER,
WEIGHT_100,
WEIGHT_200,
WEIGHT_300,
WEIGHT_400,
WEIGHT_500,
WEIGHT_600,
WEIGHT_700,
WEIGHT_800,
WEIGHT_900,
explicit_defaulting_constants=[INHERIT],
)

######################################################################
# 15.7 Font size
######################################################################
# font_size

# <absolute-size>
XX_SMALL = 'xx-small'
X_SMALL = 'x-small'
SMALL = 'small'
MEDIUM = 'medium'
LARGE = 'large'
X_LARGE = 'x-large'
XX_LARGE = 'xx-large'

# <relative-size>
LARGER = 'larger'
SMALLER = 'smaller'

FONT_SIZE_CHOICES = Choices(
XX_SMALL,
X_SMALL,
SMALL,
MEDIUM,
LARGE,
X_LARGE,
XX_LARGE,
LARGER,
SMALLER,
validators=[is_length, is_percentage],
explicit_defaulting_constants=[INHERIT],
)

######################################################################
# 15.8 Font shorthand
######################################################################

ICON = 'icon'
CAPTION = 'caption'
MENU = 'menu'
MESSAGE_BOX = 'message-box'
SMALL_CAPTION = 'small-caption'
STATUS_BAR = 'status-bar'

SYSTEM_FONT_KEYWORDS = [ICON, CAPTION, MENU, MESSAGE_BOX, SMALL_CAPTION, STATUS_BAR]

INITIAL_FONT_VALUES = {
'font_style': NORMAL,
'font_variant': NORMAL,
'font_weight': NORMAL,
'font_size': MEDIUM,
'line_height': NORMAL,
goanpeca marked this conversation as resolved.
Show resolved Hide resolved
'font_family': FontFamily([INITIAL]), # TODO: Depends on user agent. What to use?
}

######################################################################
# 16. Text ###########################################################
######################################################################
Expand Down
Loading