@@ -0,0 +1,545 @@
1+module Main exposing (main)
3+{-| Line Height as its specified through CSS doesn't make a whole lot of sense typographically.
5+We also run into issues with sizing a font. The font size generally refers to the full type size (from the top of ascendors to the bottom of descenders)
7+However, sometimes we might want to size things from the top of the Capital to the baseline.
9+Or from the top of the x-height to the baseline.
11+The main place this shows up is for dropped capitals, and for text on buttons.
16+import Element exposing (..)
17+import Element.Background as Background
18+import Element.Border as Border
19+import Element.Font as Font
20+import Element.Input as Input
23+import Html.Attributes
26+type alias FontAdjustment =
40+ = UpdateAdjustment FontAdjustment
64+ convertAdjustment default
66+ { url = Just "https://fonts.googleapis.com/css?family=EB+Garamond"
67+ , name = "EB Garamond"
69+ { capital = default.capital
70+ , lowercase = default.lowercase
71+ , baseline = default.baseline
72+ , descender = default.descender
91+ convertAdjustment default
93+ { url = Just "https://fonts.googleapis.com/css?family=Catamaran"
96+ { capital = default.capital
97+ , lowercase = default.lowercase
98+ , baseline = default.baseline
99+ , descender = default.descender
118+ convertAdjustment default
120+ { url = Just "https://fonts.googleapis.com/css?family=Poiret+One"
121+ , name = "Poiret One"
123+ { capital = default.capital
124+ , lowercase = default.lowercase
125+ , baseline = default.baseline
126+ , descender = default.descender
145+ convertAdjustment default
147+ { url = Just "https://fonts.googleapis.com/css?family=Roboto"
150+ { capital = default.capital
151+ , lowercase = default.lowercase
152+ , baseline = default.baseline
153+ , descender = default.descender
171+ UpdateAdjustment adj ->
178+ , converted = convertAdjustment adj
182+ { capital = adj.capital
183+ , lowercase = adj.lowercase
184+ , baseline = adj.baseline
185+ , descender = adj.descender
201+ [ above (html (Html.node "style" [] [ Html.text """
207+ line-height: normal;
211+ , Background.color (rgba 1 1 1 1)
213+ , Font.color (rgba 0 0 0 1)
216+ -- { url = "https://fonts.googleapis.com/css?family=EB+Garamond"
217+ -- , name = "EB Garamond"
220+ -- { url = "https://fonts.googleapis.com/css?family=Catamaran"
221+ -- , name = "Catamaran"
229+ column [ width fill, height fill, spacing 128 ]
230+ [ adjustor 120 model.adjustment
231+ , adjusted 120 model.converted
236+ htmlAttribute (Html.Attributes.style name val)
240+ htmlAttribute (Html.Attributes.class name)
247+adjustor size adjustment =
250+ [ viewAdjustment "Type Height" adjustment.capital size 180 adjustment.lineHeight (\capital -> { adjustment | capital = capital })
251+ , viewAdjustment "Lowercase Height" adjustment.lowercase size 60 adjustment.lineHeight (\lowercase -> { adjustment | lowercase = lowercase })
252+ , viewAdjustment "Baseline" adjustment.baseline size 120 adjustment.lineHeight (\baseline -> { adjustment | baseline = baseline })
253+ , viewAdjustment "Descender" adjustment.descender size 0 adjustment.lineHeight (\descender -> { adjustment | descender = descender })
259+ , Background.color (rgb 0 0.8 0.9)
261+ , style "line-height" (String.fromFloat adjustment.lineHeight)
267+ -- , height (px (round (toFloat size * (1 / 1.5))))
269+ , Background.color (rgb 0.9 0.8 0)
280+adjusted size adjustment =
286+ [ el [ Font.size 32 ] (text "Standard Defaults in CSS")
292+ [ Background.color (rgb 0 0.8 0.9)
293+ , style "line-height" "normal"
295+ , above (el [ Font.size 12 ] (text "line-height: normal"))
299+ [ Background.color (rgb 0 0.8 0.9)
300+ , style "line-height" "1"
301+ , above (el [ Font.size 12 ] (text "line-height: 1"))
307+ (text "New Adjustments in Els")
312+ [ --corrected adjustment.full "corrected"
313+ -- , corrected adjustment.capital "corrected capital"
315+ [ Font.sizeByCapital
316+ , Background.color (rgb 0 0.8 0.9)
317+ , above (el [ Font.size 12, moveUp 6 ] (text "corrected capital"))
323+ , Background.color (rgb 0.9 0.8 0)
329+ , row [ spacing 120 ]
336+ , above (el [ Font.size 32, moveUp 32 ] (text "Normal Paragraphs"))
338+ [ el [ Font.size 55, alignLeft, Background.color (rgb 0.9 0.8 0) ] (text "L")
339+ , text "orem Ipsum is simply dummy text of the printing and typesetting industry."
351+ , Background.color (rgba 0.9 0.8 0.2 0.5)
360+ , Background.color (rgba 0 0 0 0.5)
367+ (el [ Font.size 32, moveUp 32 ] (text "Corrected Paragraphs"))
372+ , Background.color (rgb 0.9 0.8 0)
373+ , Font.sizeByCapital
376+ , text "ontrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32."
382+corrected converted label =
384+ [ Background.color (rgb 0 0.8 0.9)
385+ , style "display" "block"
386+ , above (el [ Font.size 12, moveUp 6 ] (text label))
387+ , style "line-height" (String.fromFloat converted.height)
389+ (column [ Font.size 12, spacing 5, moveDown 10 ]
390+ [ text ("height: " ++ String.left 5 (String.fromFloat converted.height))
391+ , text ("vertical: " ++ String.left 5 (String.fromFloat converted.vertical))
396+ [ style "display" "inline-block"
397+ , style "line-height" (String.fromFloat converted.height)
398+ , style "vertical-align" (String.fromFloat converted.vertical ++ "em")
404+convertAdjustment adjustment =
407+ adjustment.lineHeight
410+ (adjustment.lineHeight - 1)
414+ adjustment.lineHeight / 2
417+ ((ascender - newBaseline) / 2) + newBaseline
420+ ((ascender - descender) / 2) + descender
423+ [ adjustment.capital
424+ , adjustment.baseline
425+ , adjustment.descender
426+ , adjustment.lowercase
430+ Maybe.withDefault adjustment.capital (List.maximum lines)
433+ Maybe.withDefault adjustment.descender (List.minimum lines)
437+ |> List.filter (\x -> x /= descender)
439+ |> Maybe.withDefault adjustment.baseline
442+ (oldMiddle - newCapitalMiddle) * 2
445+ (oldMiddle - newFullMiddle) * 2
448+ { vertical = fullVertical
450+ (ascender - descender)
454+ { vertical = capitalVertical
455+ , height = (ascender - newBaseline) - abs capitalVertical
460+viewAdjustment label adjustment size left lineHeight updateWith =
469+ -- , moveUp (0.125 * toFloat size)
470+ , height (px (round (toFloat size * lineHeight)))
475+ , Element.behindContent
477+ [ Element.width (Element.px 1)
478+ , Element.height Element.fill
480+ , Background.color charcoal
485+ , height (px (round fullHeight))
488+ , Background.color charcoal
489+ , below (el [ centerX ] (text (String.fromFloat adjustment)))
496+ , moveUp (fullHeight * (adjustment / lineHeight))
497+ , Border.color (rgb 0 0 0)
509+ { label = Input.labelHidden "font adjustment"
519+ [ Element.width (Element.px 16)
520+ , Element.height (Element.px 16)
523+ , Border.color (Element.rgb 0.5 0.5 0.5)
524+ , Background.color (Element.rgb 1 1 1)
529+ -- , width (px 1200)
531+ -- , Border.color (rgb 0 0 0)
533+ -- , Border.widthEach
543+ , value = adjustment