scalacss icon indicating copy to clipboard operation
scalacss copied to clipboard

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

Open helllamer opened this issue 8 years ago • 8 comments

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 avatar Sep 06 '17 10:09 helllamer

@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 avatar Sep 06 '17 10:09 helllamer

I've suddenly found very simple workaround in docs:

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

Close this PR?

helllamer avatar Sep 06 '17 14:09 helllamer

@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.

djneades avatar Sep 06 '17 14:09 djneades

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

helllamer avatar Sep 06 '17 15:09 helllamer

@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.)

djneades avatar Sep 06 '17 15:09 djneades

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

Will wait for @japgolly 's opinion.

helllamer avatar Sep 06 '17 16:09 helllamer

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 ,

helllamer avatar Sep 06 '17 18:09 helllamer

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

japgolly avatar Oct 31 '17 08:10 japgolly