Skip to content

Commit

Permalink
Font name strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Apr 9, 2017
1 parent 61fdc69 commit d144fdf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
33 changes: 20 additions & 13 deletions pandas/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,26 @@ def build_font(self, props):
assert size.endswith('pt')
size = float(size[:-2])

# TODO:
# re.search(r'''(?x)
# (
# "(?:[^"]|\\")+"
# |
# '(?:[^']|\\')+'
# |
# [^'"]+
# )(?=,|\s*$)
# ''')
font_names = [name.strip()
for name in props.get('font-family', '').split(',')
if name.strip()]
font_names_tmp = re.findall(r'''(?x)
(
"(?:[^"]|\\")+"
|
'(?:[^']|\\')+'
|
[^'",]+
)(?=,|\s*$)
''', props.get('font-family', ''))
font_names = []
for name in font_names_tmp:
if name[:1] == '"':
name = name[1:-1].replace('\\"', '"')
elif name[:1] == '\'':
name = name[1:-1].replace('\\\'', '\'')
else:
name = name.strip()
if name:
font_names.append(name)

family = None
for name in font_names:
if name == 'serif':
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/formats/test_to_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
# FONT
# - name
('font-family: foo,bar', {'font': {'name': 'foo'}}),
pytest.mark.xfail(('font-family: "foo bar",baz',
{'font': {'name': 'foo bar'}})),
('font-family: "foo bar",baz', {'font': {'name': 'foo bar'}}),
('font-family: foo,\nbar', {'font': {'name': 'foo'}}),
('font-family: foo, bar, baz', {'font': {'name': 'foo'}}),
('font-family: bar, foo', {'font': {'name': 'bar'}}),
('font-family: \'foo bar\', baz', {'font': {'name': 'foo bar'}}),
('font-family: \'foo \\\'bar\', baz', {'font': {'name': 'foo \'bar'}}),
('font-family: "foo \\"bar", baz', {'font': {'name': 'foo "bar'}}),
('font-family: "foo ,bar", baz', {'font': {'name': 'foo ,bar'}}),
# - family
('font-family: serif', {'font': {'name': 'serif', 'family': 1}}),
('font-family: Serif', {'font': {'name': 'serif', 'family': 1}}),
('font-family: roman, serif', {'font': {'name': 'roman', 'family': 1}}),
('font-family: roman, sans-serif', {'font': {'name': 'roman',
'family': 2}}),
Expand Down

0 comments on commit d144fdf

Please sign in to comment.