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

Added support for font images #9195

Merged
merged 2 commits into from Oct 12, 2016
Merged

Added support for font images #9195

merged 2 commits into from Oct 12, 2016

Conversation

cajus
Copy link
Contributor

@cajus cajus commented Sep 28, 2016

This commit adds:

  • makes the generator inspect a given font and extract needed
    information about glyphs and their aspect ratio
  • support for managed webfonts in qx.ui.basic.Image
  • support for managed webfonts in qx.ui.table.cellrenderer.Image
  • extends the Image demo in the demobrowser
  • adds a new IconFont demo in the demobrowser
  • adds some documentation for using font images

var styles = font.getStyles();
styles['width'] = style.width;
styles['height'] = style.height;
styles['fontSize'] = (style.width > style.height ? style.height : style.width) + "px";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qx.ui.table.cellrenderer.AbstractImage._getContentHtml() already adds "px" to the width/height, so the comparison can not work here and the "px" suffix is redundant

@peuter
Copy link
Contributor

peuter commented Sep 29, 2016

There should be an isFont-check added to https://github.com/cajus/qooxdoo/blob/e21fb220a5fd33dfce580bc5650e8336d255538e/framework/source/class/qx/bom/element/Decoration.js#L237 otherwise the warning is triggered on every font-icon

}

this.__updateContentHint(size, size);
el.setStyle("font-size", size + "px");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be fontSize and the whole size-handling is also done in this.__setSource (which is called in line 749) so the size handling here might be redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly redundant. There's some difference between the width/height handlings. Needs.

if (this.getScale()) {
var width = this.getWidth() || this.getHeight() || 40;
var height = this.getHeight() || this.getWidth() || 40;
el.setStyle("font-size", (width > height ? height : width) + "px");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be fontSize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is automatically converted as far as I see.

}
else {
var font = qx.theme.manager.Font.getInstance().resolve(this.getSource().match(/@([^/]+)/)[1]);
el.setStyle("font-size", font.getSize() + "px");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be fontSize

var font = qx.theme.manager.Font.getInstance().resolve(source.match(/@([^/]+)/)[1]);
el.setStyles(font.getStyles());
el.setStyle("display", "table-cell");
el.setStyle("vertical-align", "middle");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be verticalAlign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

el.setStyles(font.getStyles());
el.setStyle("display", "table-cell");
el.setStyle("vertical-align", "middle");
el.setStyle("text-align", "center");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be textAlign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

el.setStyle("text-align", "center");

if (this.getScale()) {
el.setStyle("font-size", (this.__width > this.__height ? this.__height : this.__width) + "px");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be fontSize


if (this.getScale()) {
el.setStyle("font-size", (this.__width > this.__height ? this.__height : this.__width) + "px");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also width/height must be set here, on order to override the values set by el.setStyles(font.getStyles()) in line 884

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That needs inspection.

}
else {
el.setStyle("font-size", font.getSize() + "px");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else part is obsolete as the value has already been set in line 884 el.setStyles(font.getStyles())

var ResourceManager = qx.util.ResourceManager.getInstance();
var font = qx.theme.manager.Font.getInstance().resolve(source.match(/@([^/]+)/)[1]);

var styles = font.getStyles();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The font styles map must be cloned otherwise the original map would be manipulated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider this a bug. It should not be possible to modify internal stuff. I'd expect that map to be usable directly.

_applyTextColor : function(value)
{
if (this.__getMode() === "font") {
if (value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the content element should be retrieved by

var el = this.getContentElement();
if (this.__wrapper) {
  el = el.getChild(0);
}

as it's done in e.g. _applyDecorator above.

if (isFont) {
var ResourceManager = qx.util.ResourceManager.getInstance();
var font = qx.theme.manager.Font.getInstance().resolve(source.match(/@([^/]+)/)[1]);
el.setStyles(font.getStyles());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might override styles already set by the Appearance (e.g. color), so it needs some checks here to prevent such behaviour although I currently do not know what would be the best strategy here.

This commit adds:

 * makes the generator inspect a given font and extract needed
   information about glyphs and their aspect ratio
 * support for managed webfonts in qx.ui.basic.Image
 * support for managed webfonts in qx.ui.table.cellrenderer.Image
 * extends the Image demo in the demobrowser
 * adds a new IconFont demo in the demobrowser
 * adds some documentation for using font images
@cajus
Copy link
Contributor Author

cajus commented Sep 30, 2016

Just squashed to get rid of the multiple commits.

@level420
Copy link
Member

level420 commented Oct 5, 2016

@cajus does this PR need existing apps to be changed if they do NOT want to use font images?
Just because the PR is so large and I really don't overlook all the implications of it.

@cajus
Copy link
Contributor Author

cajus commented Oct 5, 2016

Everything is like it was before, no change is required.

@level420
Copy link
Member

level420 commented Oct 5, 2016

OK then. I've walked over the code and could not find anything what seems to harm. Using font images has to wait as I've currently no time for this.
Well then let's start voting/approving.

@level420 level420 added the VOTING label Oct 5, 2016
Copy link
Member

@johnspackman johnspackman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, not tested it but all i can see is two minor typos. Looking forward to seeing this hit master, it's a great addition, well done @cajus

Drawbacks
=========

Only qx.ui.basic.Image and qx.ui.table.cellrendere.Image support icon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: qx.ui.table.cellrenderer.Image

# http://qooxdoo.org
#
# Copyright:
# 2006-2010 1&1 Internet AG, Germany, http://www.1und1.de
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright 1&1 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! And MIT License!

@level420 level420 merged commit 6037ce6 into qooxdoo:master Oct 12, 2016
@level420
Copy link
Member

3 approvals, more than 2 business days
merging
Thank you @cajus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants