Skip to content

Commit

Permalink
Merge pull request #52 from gfngfn/fix-weight-class
Browse files Browse the repository at this point in the history
Fix how to handle `OS/2`'s `usWeightClass`
  • Loading branch information
gfngfn authored Sep 29, 2023
2 parents 5d42663 + e4bcebe commit 0a8974d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/decodeError.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type t =
| UnexpectedMacStyle of int
| UnknownCharstringToken of int
| NegativeLengthForBytes of int
| UnknownWeightClass of int
| InvalidWeightClass of int
| UnknownWidthClass of int
| InvalidFsType of int
| InvalidFsSelection of int
Expand Down
18 changes: 6 additions & 12 deletions src/decodeOs2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ open DecodeBasic
open DecodeOperation.Open


let d_weight_class : Value.Os2.weight_class decoder =
let d_weight_class : int decoder =
let open DecodeOperation in
d_uint16 >>= function
| 100 -> return Value.Os2.WeightThin
| 200 -> return Value.Os2.WeightExtraLight
| 300 -> return Value.Os2.WeightLight
| 400 -> return Value.Os2.WeightNormal
| 500 -> return Value.Os2.WeightMedium
| 600 -> return Value.Os2.WeightSemiBold
| 700 -> return Value.Os2.WeightBold
| 800 -> return Value.Os2.WeightExtraBold
| 900 -> return Value.Os2.WeightBlack
| n -> err @@ UnknownWeightClass(n)
d_uint16 >>= fun n ->
if (1 <= n && n <= 1000) then
return n
else
err @@ InvalidWeightClass(n)


let d_width_class : Value.Os2.width_class decoder =
Expand Down
1 change: 1 addition & 0 deletions src/encodeError.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type t =
| NotEncodableAsUint32 of wint
| NotEncodableAsInt32 of wint
| NotEncodableAsTimestamp of wint
| InvalidWeightClass of int
| NotA10BytePanose of string
| NotA4ByteAchVendId of string
| Version4FsSelection of Value.Os2.fs_selection
Expand Down
19 changes: 5 additions & 14 deletions src/encodeOs2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,12 @@ let e_extension1 ((ext1, ext2_option) : extension1) =
return ()


let e_weight_class (weight_class : Value.Os2.weight_class) =
let e_weight_class (weight_class : int) =
let open EncodeOperation in
let u =
match weight_class with
| Value.Os2.WeightThin -> 100
| Value.Os2.WeightExtraLight -> 200
| Value.Os2.WeightLight -> 300
| Value.Os2.WeightNormal -> 400
| Value.Os2.WeightMedium -> 500
| Value.Os2.WeightSemiBold -> 600
| Value.Os2.WeightBold -> 700
| Value.Os2.WeightExtraBold -> 800
| Value.Os2.WeightBlack -> 900
in
e_uint16 u
if (1 <= weight_class && weight_class <= 1000) then
e_uint16 weight_class
else
err @@ InvalidWeightClass(weight_class)


let e_width_class (width_class : Value.Os2.width_class) =
Expand Down
17 changes: 3 additions & 14 deletions src/otfed.mli
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,6 @@ module Value : sig

(** Defines types for master data in [OS/2] tables. *)
module Os2 : sig
type weight_class =
| WeightThin
| WeightExtraLight
| WeightLight
| WeightNormal
| WeightMedium
| WeightSemiBold
| WeightBold
| WeightExtraBold
| WeightBlack
[@@deriving show]

type width_class =
| WidthUltraCondensed
| WidthExtraCondensed
Expand Down Expand Up @@ -283,7 +271,7 @@ module Value : sig
[@@deriving show]

type t = {
us_weight_class : weight_class;
us_weight_class : int; (* values from 1 to 1000. *)
us_width_class : width_class;
fs_type : fs_type;
y_subscript_x_size : design_units;
Expand Down Expand Up @@ -979,7 +967,7 @@ module Decode : sig
| UnexpectedMacStyle of int
| UnknownCharstringToken of int
| NegativeLengthForBytes of int
| UnknownWeightClass of int
| InvalidWeightClass of int
| UnknownWidthClass of int
| InvalidFsType of int
| InvalidFsSelection of int
Expand Down Expand Up @@ -1475,6 +1463,7 @@ module Encode : sig
| NotEncodableAsUint32 of wint
| NotEncodableAsInt32 of wint
| NotEncodableAsTimestamp of wint
| InvalidWeightClass of int
| NotA10BytePanose of string
| NotA4ByteAchVendId of string
| Version4FsSelection of Value.Os2.fs_selection
Expand Down
14 changes: 1 addition & 13 deletions src/value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,6 @@ module Hhea = struct
end

module Os2 = struct
type weight_class =
| WeightThin
| WeightExtraLight
| WeightLight
| WeightNormal
| WeightMedium
| WeightSemiBold
| WeightBold
| WeightExtraBold
| WeightBlack
[@@deriving show { with_path = false }]

type width_class =
| WidthUltraCondensed
| WidthExtraCondensed
Expand Down Expand Up @@ -503,7 +491,7 @@ module Os2 = struct
[@@deriving show { with_path = false }]

type t = {
us_weight_class : weight_class;
us_weight_class : int; (* values from 1 to 1000. *)
us_width_class : width_class;
fs_type : fs_type;
y_subscript_x_size : design_units;
Expand Down
2 changes: 1 addition & 1 deletion test/testCaseOs21.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let marshaled =
let unmarshaled =
Intermediate.Os2.{
value = Value.Os2.{
us_weight_class = WeightNormal;
us_weight_class = 400;
us_width_class = WidthMedium;

fs_type = Value.Os2.{
Expand Down

0 comments on commit 0a8974d

Please sign in to comment.