Skip to content

support html5 embedded font input text via @font-face #85

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 21 additions & 3 deletions src/ru/stablex/ui/widgets/InputText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import flash.events.Event;
*/
class InputText extends Text{

#if html5
public var fontFamily : String;
public var fontPath : String;
static var familyMap : Map<String, js.html.StyleElement>;
#end

/**
* Constructor
*
Expand All @@ -32,6 +38,9 @@ class InputText extends Text{
}else{
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "nowrap";
}
if( this.label.embedFonts && fontFamily != null ){
this.label.mFace = fontFamily;
}
});
#end

Expand All @@ -45,9 +54,6 @@ class InputText extends Text{
*
*/
override public function refresh () : Void {
this.label.width = this.w - this.paddingLeft - this.paddingRight;
this.label.height = this.h - this.paddingTop - this.paddingBottom;

super.refresh();

#if html5
Expand All @@ -58,6 +64,18 @@ class InputText extends Text{
}else{
Reflect.field(this.label, '__graphics').__surface.style.whiteSpace = "nowrap";
}
if( this.label.embedFonts ){
if( fontFamily != null ){
this.label.mFace = fontFamily;
if( familyMap == null ) familyMap = new Map();
if( !familyMap.exists(fontFamily) ){
var css = js.Browser.document.createStyleElement();
js.Browser.document.getElementsByTagName("head")[0].appendChild( css );
css.innerHTML = "@font-face { font-family: " + fontFamily + "; src: url('" + fontPath + "'); }";
familyMap.set(fontFamily, css);
}
}
}
#end
}//function refresh()

Expand Down
2 changes: 2 additions & 0 deletions src/ru/stablex/ui/widgets/Text.hx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Text extends Box{
*
*/
override public function refresh() : Void {
this.label.width = this.w - this.paddingLeft - this.paddingRight;
this.label.height = this.h - this.paddingTop - this.paddingBottom;
if( this.highlighted ){
this.label.defaultTextFormat = this.highlightFormat;
if( this.label.text.length > 0 ){
Expand Down