diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index b72376a..823975f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'tech.nevets.vcardgen' -version '1.0' +version '1.1' repositories { mavenCentral() diff --git a/src/main/java/tech/nevets/vcardgen/Main.java b/src/main/java/tech/nevets/vcardgen/Main.java index 1eedfce..1337ae8 100644 --- a/src/main/java/tech/nevets/vcardgen/Main.java +++ b/src/main/java/tech/nevets/vcardgen/Main.java @@ -17,9 +17,11 @@ public class Main { private static final Color GREEN = new Color(101, 142, 61); private static final Font ARIAL65 = new Font("Arial", Font.PLAIN, 65); + private static final Font ARIAL55 = new Font("Arial", Font.PLAIN, 55); private static final Font ARIAL45 = new Font("Arial", Font.PLAIN, 45); private static final Font ARIAL45I = new Font("Arial", Font.ITALIC, 45); - private static final Font ARIAL44 = new Font("Arial", Font.ITALIC, 44); + private static final Font ARIAL44I = new Font("Arial", Font.ITALIC, 44); + private static final Font ARIAL40I = new Font("Arial", Font.ITALIC, 40); private static final Font ARIAL38 = new Font("Arial", Font.ITALIC, 38); public static void main(String[] args) { @@ -49,12 +51,28 @@ public class Main { g.drawImage(background, 0, 0, null); + FontMetrics fm = g.getFontMetrics(ARIAL65); + g.setColor(WHITE); - g.setFont(ARIAL65); + if (fm.stringWidth(name) <= 969){ + g.setFont(ARIAL65); + } else { + g.setFont(ARIAL55); + } g.drawString(name, 85, 112); - g.setFont(ARIAL45I); - g.drawString(title, 91, 176); + fm = g.getFontMetrics(ARIAL45I); + if (fm.stringWidth(title) <= 970) { + g.setFont(ARIAL45I); + } else { + g.setFont(ARIAL40I); + } + g.drawString(title, 89, 176); + + boolean directLine = false; + if (hasExtension && extension.length() == 0) { + directLine = true; + } int yOffset = 0; if (hasExtension && hasCell) { @@ -65,7 +83,7 @@ public class Main { g.drawString(email, 62, 380 - yOffset); g.setColor(GREEN); - g.setFont(ARIAL44); + g.setFont(ARIAL44I); g.drawString(location, 59, 447 - yOffset); g.setFont(ARIAL38); @@ -73,7 +91,11 @@ public class Main { String number = ""; if (hasExtension && !hasCell) { - number = "W: " + schoolNumber + " x" + extension; + if (directLine) { + number = "W: " + schoolNumber; + } else { + number = "W: " + schoolNumber + " x" + extension; + } } else if (!hasExtension && hasCell) { number = "C: " + cellNumber; } @@ -81,7 +103,11 @@ public class Main { if (!(hasExtension && hasCell)) { g.drawString(number, 59, 536); } else { - g.drawString("W: " + schoolNumber + " x" + extension, 59, 496); + if (directLine) { + g.drawString("W: " + schoolNumber, 59, 496); + } else { + g.drawString("W: " + schoolNumber + " x" + extension, 59, 496); + } g.drawString("C: " + cellNumber, 59, 540); }