Przeglądaj źródła

[flash] support specifying fontWeight and fontStyle in @:font

Dan Korostelev 6 lat temu
rodzic
commit
38e9062f04
3 zmienionych plików z 28 dodań i 5 usunięć
  1. 10 0
      libs/ttflib/tTFData.ml
  2. 2 2
      libs/ttflib/tTFSwfWriter.ml
  3. 16 3
      src/generators/genswf.ml

+ 10 - 0
libs/ttflib/tTFData.ml

@@ -344,7 +344,17 @@ type ttf = {
 	ttf_kern : kern option;
 }
 
+type ttf_font_weight =
+	| TFWRegular
+	| TFWBold
+
+type ttf_font_posture =
+	| TFPNormal
+	| TFPItalic
+
 type ttf_config = {
 	mutable ttfc_range_str : string;
 	mutable ttfc_font_name : string option;
+	mutable ttfc_font_weight : ttf_font_weight;
+	mutable ttfc_font_posture : ttf_font_posture;
 }

+ 2 - 2
libs/ttflib/tTFSwfWriter.ml

@@ -200,8 +200,8 @@ let to_swf ttf config =
 		font_is_ansi = false;
 		font_wide_offsets = true;
 		font_wide_codes = true;
-		font_is_italic = false;
-		font_is_bold = false;
+		font_is_italic = config.ttfc_font_posture = TFPItalic;
+		font_is_bold = config.ttfc_font_weight = TFWBold;
 		font_language = LCNone;
 		font_name = (match config.ttfc_font_name with Some s -> s | None -> ttf.ttf_font_name);
 		font_glyphs = glyfs;

+ 16 - 3
src/generators/genswf.ml

@@ -276,12 +276,14 @@ let build_swf9 com file swc =
 					let ttf = try TTFParser.parse ch with e -> abort ("Error while parsing font " ^ file ^ " : " ^ Printexc.to_string e) p in
 					close_in ch;
 					let get_string e = match fst e with
-						| EConst (String s) -> Some s
+						| EConst (String s) -> s
 						| _ -> raise Not_found
 					in
 					let ttf_config = {
 						ttfc_range_str = "";
 						ttfc_font_name = None;
+						ttfc_font_weight = TFWRegular;
+						ttfc_font_posture = TFPNormal;
 					} in
 					begin match args with
 						| (EConst (String str),_) :: _ -> ttf_config.ttfc_range_str <- str;
@@ -291,8 +293,19 @@ let build_swf9 com file swc =
 						| _ :: [e] ->
 							begin match fst e with
 								| EObjectDecl fl ->
-									begin try ttf_config.ttfc_font_name <- get_string (Expr.field_assoc "fontName" fl)
-									with Not_found -> () end
+									(try ttf_config.ttfc_font_name <- Some(get_string (Expr.field_assoc "fontName" fl)) with Not_found -> ());
+									(try ttf_config.ttfc_font_weight <- (
+										match get_string (Expr.field_assoc "fontWeight" fl) with
+										| "regular" -> TFWRegular
+										| "bold" -> TFWBold
+										| _ -> abort "Invalid fontWeight value. Must be `regular` or `bold`." p
+									) with Not_found -> ());
+									(try ttf_config.ttfc_font_posture <- (
+										match get_string (Expr.field_assoc "fontStyle" fl) with
+										| "normal" -> TFPNormal
+										| "italic" -> TFPItalic
+										| _ -> abort "Invalid fontStyle value. Must be `normal` or `italic`." p
+									) with Not_found -> ());
 								| _ ->
 									()
 							end