Skip to content

fontFamily(): allow string value for font-family attribute#121

Open
helllamer wants to merge 1 commit into
japgolly:masterfrom
suggestio:master
Open

fontFamily(): allow string value for font-family attribute#121
helllamer wants to merge 1 commit into
japgolly:masterfrom
suggestio:master

Conversation

@helllamer

@helllamer helllamer commented Sep 6, 2017

Copy link
Copy Markdown

Currently, it is not possible to use font-faces from external CSS-files:
fontFamily.apply() allow only FontFace instances.

This commit allows to specify raw font-family string value, making possible to use non-inline fonts faces.

@helllamer

Copy link
Copy Markdown
Author

@japgolly, it looks like, there are an issues with travis-ci build, not related to this commit:

[error] phantomjs: error while loading shared libraries: libicui18n.so.48: cannot open shared object file: No such file or directory

@helllamer

Copy link
Copy Markdown
Author

I've suddenly found very simple workaround in docs:

fontFamily.attr := "times-new-roman"

Close this PR?

@djneades

djneades commented Sep 6, 2017

Copy link
Copy Markdown

@helllamer I’ve been doing this to use default/local fonts:

fontFamily :=! "monospace"

It’s ugly to have to use the ! to avoid the warning, but it does work.

@helllamer

Copy link
Copy Markdown
Author

@dneades Yes, thanks. It looks like, := also works without warning against fontFamily.attr.

@djneades

djneades commented Sep 6, 2017

Copy link
Copy Markdown

@helllamer I hadn’t known that .attr was a possibility until I saw your original comment. I think, in this case, that it would be nice if fontFamily := "something" were to work without a warning, since I suspect that the most frequent use of fontFamily will be with default/local fonts. I know that isn’t typesafe, though, and I suppose the extra .attr or ! isn’t the end of the world. (I did spend some time being puzzled when I was first trying to work out how to use fontFamily, though! It would be nice if the documentation covered this common usage.)

@helllamer

Copy link
Copy Markdown
Author

@dneades Thanks for response. I agree, using fontFamily looks unclear/tricky for scalaCSS end-users.

Will wait for @japgolly 's opinion.

@helllamer

Copy link
Copy Markdown
Author

Observed another possible-dangerous situation with using := or :=? against fontFamily.
CSS font-family may contain comma-separated sequence of names, some of names may need quoting, for example:

font-family: verdana, "times new roman", "10ttf"

Possible solution is to implement attr constructor with like that:

fontFamily.apply(name1: String, names: String*): AV
val myFont1 = fontFamily("some-font-family")
val myFont2 = fontFamily("pn10din xfont", "confic", "gazzelle")

Such method will force "-quoting for each family name, and will concat all strings via ,

@japgolly

Copy link
Copy Markdown
Owner

Sorry for the delay. Varargs seems like a good and reasonable way to go

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.

3 participants