-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Render small-caps font variant #1611
Open
samizdatco
wants to merge
7
commits into
Automattic:master
Choose a base branch
from
samizdatco:font-variant-css-2.1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
48059a5
render small-caps font variant
samizdatco 56260c7
added small-caps feature to CHANGELOG
samizdatco ed7d4a1
added textAttributes field to state struct
samizdatco 4d205f7
only set opentype features on sufficiently new versions of pango
samizdatco 7df005d
skip the small-caps variant test on windows
samizdatco 1082954
expose pango version in module
samizdatco c99281c
update tests to detect pango version
samizdatco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,7 @@ Context2d::Context2d(Canvas *canvas) { | |
Context2d::~Context2d() { | ||
while(stateno >= 0) { | ||
pango_font_description_free(states[stateno]->fontDescription); | ||
pango_attr_list_unref(states[stateno]->textAttributes); | ||
free(states[stateno--]); | ||
} | ||
g_object_unref(_layout); | ||
|
@@ -213,6 +214,7 @@ Context2d::~Context2d() { | |
void Context2d::resetState(bool init) { | ||
if (!init) { | ||
pango_font_description_free(state->fontDescription); | ||
pango_attr_list_unref(states[stateno]->textAttributes); | ||
} | ||
|
||
state->shadowBlur = 0; | ||
|
@@ -235,6 +237,8 @@ void Context2d::resetState(bool init) { | |
state->fontDescription = pango_font_description_from_string("sans serif"); | ||
pango_font_description_set_absolute_size(state->fontDescription, 10 * PANGO_SCALE); | ||
pango_layout_set_font_description(_layout, state->fontDescription); | ||
state->textAttributes = pango_attr_list_new(); | ||
pango_layout_set_attributes(_layout, state->textAttributes); | ||
|
||
_resetPersistentHandles(); | ||
} | ||
|
@@ -258,6 +262,8 @@ Context2d::save() { | |
states[++stateno] = (canvas_state_t *) malloc(sizeof(canvas_state_t)); | ||
memcpy(states[stateno], state, sizeof(canvas_state_t)); | ||
states[stateno]->fontDescription = pango_font_description_copy(states[stateno-1]->fontDescription); | ||
states[stateno]->textAttributes = pango_attr_list_copy(states[stateno-1]->textAttributes); | ||
pango_layout_set_attributes(_layout, states[stateno]->textAttributes); | ||
state = states[stateno]; | ||
} | ||
} | ||
|
@@ -271,10 +277,12 @@ Context2d::restore() { | |
if (stateno > 0) { | ||
cairo_restore(_context); | ||
pango_font_description_free(states[stateno]->fontDescription); | ||
pango_attr_list_unref(states[stateno]->textAttributes); | ||
free(states[stateno]); | ||
states[stateno] = NULL; | ||
state = states[--stateno]; | ||
pango_layout_set_font_description(_layout, state->fontDescription); | ||
pango_layout_set_attributes(_layout, state->textAttributes); | ||
} | ||
} | ||
|
||
|
@@ -2499,6 +2507,7 @@ NAN_GETTER(Context2d::GetFont) { | |
|
||
/* | ||
* Set font: | ||
* - variant | ||
* - weight | ||
* - style | ||
* - size | ||
|
@@ -2523,6 +2532,7 @@ NAN_SETTER(Context2d::SetFont) { | |
if (mparsed->IsUndefined()) return; | ||
Local<Object> font = Nan::To<Object>(mparsed).ToLocalChecked(); | ||
|
||
Nan::Utf8String variant(Nan::Get(font, Nan::New("variant").ToLocalChecked()).ToLocalChecked()); | ||
Nan::Utf8String weight(Nan::Get(font, Nan::New("weight").ToLocalChecked()).ToLocalChecked()); | ||
Nan::Utf8String style(Nan::Get(font, Nan::New("style").ToLocalChecked()).ToLocalChecked()); | ||
double size = Nan::To<double>(Nan::Get(font, Nan::New("size").ToLocalChecked()).ToLocalChecked()).FromMaybe(0); | ||
|
@@ -2547,6 +2557,16 @@ NAN_SETTER(Context2d::SetFont) { | |
context->state->fontDescription = sys_desc; | ||
pango_layout_set_font_description(context->_layout, sys_desc); | ||
|
||
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 37, 1) | ||
PangoAttribute *features; | ||
if (strlen(*variant) > 0 && strcmp("small-caps", *variant) == 0) { | ||
features = pango_attr_font_features_new("smcp 1, onum 1"); | ||
} else { | ||
features = pango_attr_font_features_new(""); | ||
} | ||
pango_attr_list_change(context->state->textAttributes, features); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a little more code, but you could instead free the attr list on the stack first, then set the a fresh attr list on the layout and stack here. That way it's a little more like the code above and we're not mutating objects on the state. |
||
#endif | ||
|
||
context->_font.Reset(value); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite rhyme with how we handle the font description on the state (continued below)