| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.github.weisj.jsvg.attributes.font; |
| 23 |
|
| 24 |
import org.jetbrains.annotations.NotNull; |
| 25 |
|
| 26 |
import com.github.weisj.jsvg.attributes.HasMatchName; |
| 27 |
import com.github.weisj.jsvg.geometry.size.Length; |
| 28 |
import com.github.weisj.jsvg.geometry.size.Unit; |
| 29 |
|
| 30 |
public enum PredefinedFontSize implements HasMatchName, FontSize { |
| 31 |
xxSmall("xx-small", 3f / 5f), |
| 32 |
xSmall("x-small", 3f / 4f), |
| 33 |
small(8f / 9f), |
| 34 |
medium(1f), |
| 35 |
large(6f / 5f), |
| 36 |
xLarge("x-large", 3f / 2f), |
| 37 |
xxLarge("xx-large", 2f), |
| 38 |
xxxLarge("xxx-large", 3f), |
| 39 |
larger(1.3f), |
| 40 |
smaller(0.7f), |
| 41 |
Number(0); |
| 42 |
|
| 43 |
private final @NotNull String matchName; |
| 44 |
private final float scalingFactor; |
| 45 |
|
| 46 |
PredefinedFontSize(@NotNull String matchName, float scalingFactor) { |
| 47 |
this.matchName = matchName; |
| 48 |
this.scalingFactor = scalingFactor; |
| 49 |
} |
| 50 |
|
| 51 |
PredefinedFontSize(float scalingFactor) { |
| 52 |
this.scalingFactor = scalingFactor; |
| 53 |
this.matchName = name(); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public @NotNull String matchName() { |
| 58 |
return matchName; |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public @NotNull Length size(@NotNull Length parentSize) { |
| 63 |
if (this == Number) throw new UnsupportedOperationException("Number font-size needs to parsed explicitly"); |
| 64 |
if (this == smaller || this == larger) return parentSize.multiply(scalingFactor); |
| 65 |
return Unit.RAW.valueOf(SVGFont.defaultFontSize() * scalingFactor); |
| 66 |
} |
| 67 |
} |