Last active
May 15, 2022 06:47
-
-
Save AnalyzePlatypus/55d806caa739ba6c2b27ede752fa3c9c to your computer and use it in GitHub Desktop.
jsPDF helper function: Convert points to other units
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertPointsToUnit(points, unit) { | |
// Unit table from https://github.com/MrRio/jsPDF/blob/ddbfc0f0250ca908f8061a72fa057116b7613e78/jspdf.js#L791 | |
var multiplier; | |
switch(unit) { | |
case 'pt': multiplier = 1; break; | |
case 'mm': multiplier = 72 / 25.4; break; | |
case 'cm': multiplier = 72 / 2.54; break; | |
case 'in': multiplier = 72; break; | |
case 'px': multiplier = 96 / 72; break; | |
case 'pc': multiplier = 12; break; | |
case 'em': multiplier = 12; break; | |
case 'ex': multiplier = 6; | |
default: | |
throw ('Invalid unit: ' + unit); | |
} | |
return points * multiplier; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你这写反了吧,应该是
convertUnitToPoints
吧。