+
@@ -74,17 +61,21 @@
import { mapGetters, mapMutations } from "vuex";
import Modal from "@/components/modal/modal";
import DocumentFactory from "@/factories/document-factory";
+import DimensionsFormatter from "@/components/ui/dimensions-formatter/dimensions-formatter";
import messages from "./messages.json";
export default {
i18n: { messages },
components: {
Modal,
+ DimensionsFormatter,
},
data: () => ({
name : "",
- width : 1000,
- height : 1000,
+ dimensions: {
+ width: 1000,
+ height: 1000,
+ },
}),
computed: {
...mapGetters([
@@ -102,9 +93,9 @@ export default {
]),
async save() {
this.addNewDocument( DocumentFactory.create({
- name: this.name,
- width: this.width,
- height: this.height
+ name : this.name,
+ width : Math.round( this.dimensions.width ),
+ height : Math.round( this.dimensions.height ),
}));
this.closeModal();
},
diff --git a/src/components/file-menu/create-document/messages.json b/src/components/file-menu/create-document/messages.json
index 3afb917..e05ce69 100644
--- a/src/components/file-menu/create-document/messages.json
+++ b/src/components/file-menu/create-document/messages.json
@@ -3,8 +3,6 @@
"newDocument": "New document",
"newDocumentNum": "New document #{num}",
"name": "Name",
- "width": "Width",
- "height": "Height",
"create": "Create",
"cancel": "Cancel"
}
diff --git a/src/components/ui/dimensions-formatter/dimensions-formatter.vue b/src/components/ui/dimensions-formatter/dimensions-formatter.vue
new file mode 100644
index 0000000..3549ae5
--- /dev/null
+++ b/src/components/ui/dimensions-formatter/dimensions-formatter.vue
@@ -0,0 +1,171 @@
+/**
+* The MIT License (MIT)
+*
+* Igor Zinken 2021 - https://www.igorski.nl
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of
+* this software and associated documentation files (the "Software"), to deal in
+* the Software without restriction, including without limitation the rights to
+* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+* the Software, and to permit persons to whom the Software is furnished to do so,
+* subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all
+* copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/ui/dimensions-formatter/messages.json b/src/components/ui/dimensions-formatter/messages.json
new file mode 100644
index 0000000..d80ed54
--- /dev/null
+++ b/src/components/ui/dimensions-formatter/messages.json
@@ -0,0 +1,13 @@
+{
+ "en-US": {
+ "dimensions": "Dimensions",
+ "dpi": "DPI",
+ "width": "Width",
+ "height": "Height",
+ "unit": "Unit",
+ "px": "Pixels",
+ "in": "Inches",
+ "cm": "Centimeters",
+ "mm": "Millimeters"
+ }
+}
diff --git a/src/math/unit-math.js b/src/math/unit-math.js
new file mode 100644
index 0000000..6104c4d
--- /dev/null
+++ b/src/math/unit-math.js
@@ -0,0 +1,31 @@
+/**
+ * The MIT License (MIT)
+ *
+ * Igor Zinken 2021 - https://www.igorski.nl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+const CM_PER_INCH = 2.54;
+const MM_PER_INCH = CM_PER_INCH * 10;
+
+export const pixelsToInch = ( pixels, dpi = 72 ) => pixels / dpi;
+export const pixelsToCm = ( pixels, dpi = 72 ) => pixelsToInch( pixels, dpi ) * CM_PER_INCH
+export const pixelsToMm = ( pixels, dpi = 72 ) => pixelsToInch( pixels, dpi ) * MM_PER_INCH;
+export const inchesToPixels = ( inches, dpi = 72 ) => inches * dpi;
+export const cmToPixels = ( cms, dpi = 72 ) => inchesToPixels( cms / CM_PER_INCH );
+export const mmToPixels = ( mms, dpi = 72 ) => inchesToPixels( mms / MM_PER_INCH );