Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tr1sm0s1n/gopdf into tr1s…
Browse files Browse the repository at this point in the history
…m0s1n-master
  • Loading branch information
oneplus1000 committed Mar 27, 2024
2 parents 4e56b66 + fc60928 commit 597b99a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ const (
UnitUnset = iota // No units were set, when conversion is called on nothing will happen
UnitPT // Points
UnitMM // Millimeters
UnitCM // centimeters
UnitIN // inches
UnitCM // Centimeters
UnitIN // Inches
UnitPX // Pixels

// The math needed to convert units to points
conversionUnitPT = 1.0
conversionUnitMM = 72.0 / 25.4
conversionUnitCM = 72.0 / 2.54
conversionUnitIN = 72.0
conversionUnitPX = 3.0 / 4.0
)

// The units that can be used in the document (for backward compatibility)
Expand All @@ -21,8 +23,9 @@ const (
Unit_Unset = UnitUnset // No units were set, when conversion is called on nothing will happen
Unit_PT = UnitPT // Points
Unit_MM = UnitMM // Millimeters
Unit_CM = UnitCM // centimeters
Unit_IN = UnitIN // inches
Unit_CM = UnitCM // Centimeters
Unit_IN = UnitIN // Inches
Unit_PX = UnitPX // Pixels
)

// Config static config
Expand Down Expand Up @@ -53,6 +56,8 @@ func UnitsToPoints(t int, u float64) float64 {
return u * conversionUnitCM
case UnitIN:
return u * conversionUnitIN
case UnitPX:
return u * conversionUnitPX
default:
return u
}
Expand All @@ -69,6 +74,8 @@ func PointsToUnits(t int, u float64) float64 {
return u / conversionUnitCM
case UnitIN:
return u / conversionUnitIN
case UnitPX:
return u / conversionUnitPX
default:
return u
}
Expand Down

0 comments on commit 597b99a

Please sign in to comment.