chiark / gitweb /
currency: Support adjusting size of the unit text, separately
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 17:55:19 +0000 (18:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 18:58:25 +0000 (19:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
docs/gamespec.rst
src/currency.rs

index aed2f8b7b12b5bcc679868526d367c98eb50cf3d..1eddf0e04e9e8a7ea474679f9d377eeef75ccd64 100644 (file)
@@ -447,6 +447,10 @@ Parameters:
  * ``label.size`` [number, default 6]:
    Font size for the value (in pixeels, svg ``px``).
 
+ * ``label.unit_rel_size`` [number, default 1]:
+   Relative font size for the unit part of the value.
+   (Proportion of the quantity.)
+
 Exammple::
 
   [[pieces]]
index 61af1ff1a59bab2eaefafb9d100a14b4be415dc2..3205011548e8452a1001aa37fd4323eec9d67fc1 100644 (file)
@@ -30,6 +30,8 @@ pub struct Spec {
 
 #[derive(Debug,Default,Clone,Serialize,Deserialize)]
 pub struct LabelSpec {
+  pub unit_rel_size: Option<f64>,
+
   #[serde(flatten,default)]
   pub options: TextOptionsSpec,
 }
@@ -39,6 +41,7 @@ pub struct Banknote {
   itemname: String,
   image: Arc<dyn InertPieceTrait>,
   currency: String,
+  unit_size: f64,
   label_options: TextOptions,
 }
 
@@ -56,10 +59,12 @@ impl PieceSpec for Spec {
   fn load(&self, PLA { gpc,ig,depth,.. }: PLA) -> SpecLoaded {
     gpc.rotateable = false;
 
-    let Spec { ref image, ref currency, qty,
-               label: LabelSpec { options: ref label_options } } = *self;
+    let Spec { ref image, ref currency, qty, label: LabelSpec {
+      options: ref label_options, unit_rel_size,
+    } } = *self;
 
     let label_options = label_options.resolve(DEFAULT_QTY_FONT_SIZE)?;
+    let unit_size = label_options.size * unit_rel_size.unwrap_or(1.);
 
     let SpecLoadedInert { p: image, occultable:_ } =
       image.load_inert(ig, depth)?;
@@ -78,7 +83,7 @@ impl PieceSpec for Spec {
     let bnote = Banknote {
       image: image.into(),
       currency: currency.clone(),
-      itemname, label_options,
+      itemname, label_options, unit_size,
     };
 
     gpc.fastsplit = FastSplitId::new_placeholder();
@@ -120,8 +125,9 @@ impl PieceTrait for Banknote {
     let value: &Value = gpc.xdata.get_exp()?;
 
     hwrite!(f,
-            r##"<{}>{}{}</text>"##,
-            &self.label_options.start_element(), value.qty, &self.currency)?;
+            r##"<{}>{}<tspan font-size="{}">{}</tspan></text>"##,
+            &self.label_options.start_element(), value.qty,
+            &self.unit_size, &self.currency)?;
   }
 
   #[throws(ApiPieceOpError)]