unihtml/sizes/sizes.go

192 lines
13 KiB
Go
Raw Normal View History

2021-02-08 19:36:06 +00:00
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
// Package sizes defines basic types that determines the size units i.e. lengths.
//
//
2021-02-23 00:54:34 +00:00
package sizes ;import (_fg "encoding/json";_a "flag";_g "fmt";_cb "strconv";_c "strings";);var _ _a .Value =(*Point )(nil );
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Millimeters converts the inches value to the millimeters.
func (_fd Inch )Millimeters ()Millimeter {return Millimeter (float64 (_fd )*_ca )};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Point is a unit of Length commonly used to measure the height of fonts.
type Point float64 ;
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// String implements fmt.Stringer interface.
func (_ba Inch )String ()string {_gfe :=_c .Builder {};_gfe .WriteString (_cb .FormatFloat (float64 (_ba ),'f',1,64));_gfe .WriteString ("\u0069\u006e");return _gfe .String ();};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// HasChanged implements viper.FlagValue interface.
func (_ge *Point )HasChanged ()bool {return _ge !=nil };
2021-02-08 19:36:06 +00:00
// Inch is a unit that
type Inch float64 ;
// Type implements pflag.Value interface.
2021-02-23 00:54:34 +00:00
func (_gd Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Orientation is the page orientation type wrapper.
type Orientation bool ;
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Set sets the unit value.
// Implements pflag.Value interface.
func (_gf *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_gf .Length =nil ;return nil ;};_df ,_ec :=UnmarshalLength (s );if _ec !=nil {return _ec ;};_gf .Length =_df ;return nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Name implements pflag.Value interface.
func (_eg Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Name implements viper.FlagValue interface.
func (_de Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};
2021-02-08 19:36:06 +00:00
// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise
2021-02-23 00:54:34 +00:00
func (_fdg PageSize )IsAPageSize ()bool {for _ ,_ffb :=range _da {if _fdg ==_ffb {return true ;};};return false ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// String implements fmt.Stringer interface.
func (_ecb Millimeter )String ()string {_ag :=_c .Builder {};_ag .WriteString (_cb .FormatFloat (float64 (_ecb ),'f',1,64));_ag .WriteString ("\u006d\u006d");return _ag .String ();};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Type implements pflag.Value interface.
func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Set implements flag.Value interface.
func (_dg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dg =Landscape ;default:return _g .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s );
};return nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// ValueType implements pflag.Value interface.
func (_fee Inch )ValueType ()string {return _fee .Type ()};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Set implements pflag.Value interface.
func (_fgd *PageSize )Set (s string )error {_cf ,_efe :=UnmarshalPageSize (s );if _efe !=nil {return _efe ;};*_fgd =_cf ;return nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// PageSizeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func PageSizeString (s string )(PageSize ,error ){if _cgc ,_fcd :=_ada [s ];_fcd {return _cgc ,nil ;};return 0,_g .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s );
};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Millimeters gets the float64 millimeter value.
func (_ea Millimeter )Millimeters ()Millimeter {return _ea };
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// PageSizeValues returns all values of the enum
func PageSizeValues ()[]PageSize {return _da };var _da =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// UnmarshalPageSize unmarshals the page size from the string.
func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _bd PageSize ;if _ecg :=(&_bd ).UnmarshalText ([]byte (pageSize ));_ecg !=nil {return 0,_g .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_ecg );
};return _bd ,nil ;};var (_ Length =Millimeter (0););var _ada =map[string ]PageSize {_ace [0:9]:0,_ace [9:11]:1,_ace [11:13]:2,_ace [13:15]:3,_ace [15:17]:4,_ace [17:19]:5,_ace [19:21]:6,_ace [21:23]:7,_ace [23:25]:8,_ace [25:27]:9,_ace [27:29]:10,_ace [29:32]:11,_ace [32:34]:12,_ace [34:36]:13,_ace [36:38]:14,_ace [38:40]:15,_ace [40:42]:16,_ace [42:44]:17,_ace [44:46]:18,_ace [46:48]:19,_ace [48:50]:20,_ace [50:52]:21,_ace [52:55]:22,_ace [55:61]:23};
func _cbab (_dc string )(Inch ,error ){_dc =_c .TrimSpace (_c .Trim (_dc ,"\u0069\u006e"));_cg ,_ed :=_cb .ParseFloat (_dc ,64);if _ed !=nil {return 0,_g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ed );
};return Inch (_cg ),nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Set implements flag.Value interface.
func (_bae *Point )Set (s string )error {_fec ,_ab :=_cb .ParseFloat (s ,64);if _ab !=nil {return _g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ab );};*_bae =Point (_fec );
return nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// String implements fmt.Stringer interface.
func (_ae Point )String ()string {_cbfc :=_c .Builder {};_cbfc .WriteString (_cb .FormatFloat (float64 (_ae ),'f',1,64));_cbfc .WriteString ("\u0070\u0074");return _cbfc .String ();};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// MarshalUnit marshals the unit into the string.
func MarshalUnit (unit Length )(string ,error ){switch _ac :=unit .(type ){case Millimeter :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ac ),nil ;case Inch :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ac ),nil ;case Point :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ac ),nil ;
default:return "",_g .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};var _ _a .Value =(*Orientation )(nil );
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// String gets the string value for given flag.
func (_e *LengthFlag )String ()string {if _e .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _e .Length .String ();};
2021-02-08 19:36:06 +00:00
// Points implements Length interface.
2021-02-23 00:54:34 +00:00
func (_ef Point )Points ()Point {return _ef };
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Millimeters converts the inches value to the millimeters.
func (_agc Point )Millimeters ()Millimeter {return Millimeter (float64 (_agc )*_dd )};
// MarshalJSON implements the json.Marshaler interface for PageSize
func (_aeg PageSize )MarshalJSON ()([]byte ,error ){return _fg .Marshal (_aeg .String ())};func (_gc PageSize )String ()string {if _gc < 0||_gc >=PageSize (len (_aa )-1){return _g .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_gc );
};return _ace [_aa [_gc ]:_aa [_gc +1]];};
// LengthFlag is a pflag wrapper for the Length value.
type LengthFlag struct{Length Length ;};
2021-02-08 19:36:06 +00:00
// UnmarshalInch unmarshalls provided string into unit.
2021-02-23 00:54:34 +00:00
func UnmarshalInch (unit string )(Inch ,error ){if _c .HasSuffix (unit ,"\u006d\u006d"){_fca ,_eca :=_bg (unit );if _eca !=nil {return 0,_eca ;};return _fca .Inches (),nil ;};if _c .HasSuffix (unit ,"\u0069\u006e"){return _cbab (unit );};return 0,_g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit );
};
2021-02-08 19:36:06 +00:00
// MarshalText implements the encoding.TextMarshaler interface for PageSize
2021-02-23 00:54:34 +00:00
func (_aed PageSize )MarshalText ()([]byte ,error ){return []byte (_aed .String ()),nil };
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Type implements pflag.Value interface.
func (_cba *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Millimeter is the dimension unit that defines a millimeter.
type Millimeter float64 ;const (Portrait =Orientation (false );Landscape =Orientation (true ););
2021-02-08 19:36:06 +00:00
// MarshalPageSize marshals the page size into string.
2021-02-23 00:54:34 +00:00
func MarshalPageSize (p PageSize )(string ,error ){_adb ,_ee :=p .MarshalText ();if _ee !=nil {return "",_ee ;};return string (_adb ),nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Points implements Length interface.
func (_fef Inch )Points ()Point {return Point (float64 (_fef )*_cbf )};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// String implements fmt.Stringer interface.
func (_baa Orientation )String ()string {if _baa ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;
B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// ValueType implements viper.FlagValue interface.
func (_ecc Point )ValueType ()string {return _ecc .Type ()};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Inches gets the inch value. Implements Length interface.
func (_feef Point )Inches ()Inch {return Inch (float64 (_feef )*_d )};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Dimensions gets the dimensions of the given page size.
// If provided page size is not valid than the function returns 0 values.
func (_adc PageSize )Dimensions ()(_cgf ,_bbe Millimeter ){switch _adc {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105;
case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125;
case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _cgf ,_bbe ;};const _ace ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072";
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// UnmarshalLength unmarshalls string value into Length.
func UnmarshalLength (length string )(Length ,error ){if _c .HasSuffix (length ,"\u006d\u006d"){return _bg (length );};if _c .HasSuffix (length ,"\u0069\u006e"){return _cbab (length );};if _c .HasSuffix (length ,"\u0070\u0074"){return _ddc (length );};
return nil ,_g .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// ValueString implements pflag.Value interface.
func (_be Inch )ValueString ()string {return _be .String ()};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Type implements pflag.Value interface.
func (_aec Point )Type ()string {return "\u0070\u006f\u0069n\u0074"};func _bg (_bf string )(Millimeter ,error ){_bf =_c .TrimSpace (_c .TrimSuffix (_bf ,"\u006d\u006d"));_fcg ,_cdd :=_cb .ParseFloat (_bf ,64);if _cdd !=nil {return 0,_g .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_cdd );
};return Millimeter (_fcg ),nil ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// ValueString implements viper.FlagValue interface.
func (_fae Point )ValueString ()string {return _fae .String ()};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Points implements Length interface.
func (_fa Millimeter )Points ()Point {return Point (_fa *_b )};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// Inches gets the inch value. Implements Length interface.
func (_egf Inch )Inches ()Inch {return _egf };
2021-02-08 19:36:06 +00:00
// Length is it the default dimension unit.
type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;};
2021-02-23 00:54:34 +00:00
// Inches gets the inches equivalent from provided millimeter value.
func (_fe Millimeter )Inches ()Inch {return Inch (float64 (_fe )*_cd )};
2021-02-08 19:36:06 +00:00
// UnmarshalJSON implements the json.Unmarshaler interface for PageSize
2021-02-23 00:54:34 +00:00
func (_dcd *PageSize )UnmarshalJSON (data []byte )error {var _cc string ;if _cde :=_fg .Unmarshal (data ,&_cc );_cde !=nil {return _g .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data );
};var _gff error ;*_dcd ,_gff =PageSizeString (_cc );return _gff ;};func _ddc (_abg string )(Point ,error ){_abg =_c .TrimSpace (_c .Trim (_abg ,"\u0070\u0074"));_ecbc ,_ad :=_cb .ParseFloat (_abg ,64);if _ad !=nil {return 0,_ad ;};return Point (_ecbc ),nil ;
};var _aa =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// HasChanged implements pflag.Value interface.
func (_bbc *Inch )HasChanged ()bool {return _bbc !=nil };
2021-02-08 19:36:06 +00:00
// Type implements pflag.Value interface.
2021-02-23 00:54:34 +00:00
func (_deb PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};var _ Length =Inch (0);const (_cd =float64 (1)/float64 (25.4);_ca =25.4;_d =0.0139;_dd =0.3528;_cbf =1/64;_b =1/_dd ;);
2021-02-08 19:36:06 +00:00
// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize
2021-02-23 00:54:34 +00:00
func (_fab *PageSize )UnmarshalText (text []byte )error {var _gee error ;*_fab ,_gee =PageSizeString (string (text ));return _gee ;};
2021-02-08 19:36:06 +00:00
2021-02-23 00:54:34 +00:00
// PageSize is the enum used for defining the page size.
type PageSize int ;
// Set implements pflag.Value interface.
func (_fc *Inch )Set (s string )error {_ff ,_fed :=_cb .ParseFloat (s ,64);if _fed !=nil {return _g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fed );};*_fc =Inch (_ff );
return nil ;};