doneish
This commit is contained in:
parent
2ca552fa23
commit
d0762c116f
@ -22,7 +22,7 @@ public class Main {
|
||||
private static final Font ARIAL45I = new Font("Arial", Font.ITALIC, 45);
|
||||
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);
|
||||
private static final Font ARIAL38I = new Font("Arial", Font.ITALIC, 38);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@ -30,7 +30,18 @@ public class Main {
|
||||
post("/", (req, res) -> {
|
||||
res.type("image/png");
|
||||
JsonObject data = new Gson().fromJson(req.body(), JsonObject.class);
|
||||
return generate(data.get("name").getAsString(), data.get("title").getAsString(), data.get("email").getAsString(), data.get("location").getAsString(), data.get("address").getAsString(), data.get("schoolNumber").getAsString(), data.get("extension").getAsString(), data.get("hasExtension").getAsBoolean(), data.get("cellNumber").getAsString(), data.get("hasCell").getAsBoolean());
|
||||
return generate(
|
||||
data.get("name").getAsString(),
|
||||
data.get("title").getAsString(),
|
||||
data.get("email").getAsString(),
|
||||
data.get("location").getAsString(),
|
||||
data.get("address").getAsString(),
|
||||
data.get("schoolNumber").getAsString(),
|
||||
data.get("extension").getAsString(),
|
||||
data.get("hasExtension").getAsBoolean(),
|
||||
data.get("cellNumber").getAsString(),
|
||||
data.get("hasCell").getAsBoolean()
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
@ -74,20 +85,50 @@ public class Main {
|
||||
directLine = true;
|
||||
}
|
||||
|
||||
int yOffset = 0;
|
||||
int doubleNumOffset = 0;
|
||||
if (hasExtension && hasCell) {
|
||||
yOffset = 40;
|
||||
doubleNumOffset = 40;
|
||||
}
|
||||
|
||||
int longAddrOffset = 0;
|
||||
fm = g.getFontMetrics(ARIAL38I);
|
||||
if (fm.stringWidth(address) > 694) {
|
||||
longAddrOffset = 40;
|
||||
}
|
||||
|
||||
g.setFont(ARIAL45);
|
||||
g.drawString(email, 62, 380 - yOffset);
|
||||
g.drawString(email, 62, 380 - doubleNumOffset - longAddrOffset);
|
||||
|
||||
g.setColor(GREEN);
|
||||
g.setFont(ARIAL44I);
|
||||
g.drawString(location, 59, 447 - yOffset);
|
||||
g.drawString(location, 59, 447 - doubleNumOffset - longAddrOffset);
|
||||
|
||||
g.setFont(ARIAL38);
|
||||
g.drawString(address, 59, 491 - yOffset);
|
||||
|
||||
StringBuilder addrLineOne = new StringBuilder();
|
||||
StringBuilder addrLineTwo = new StringBuilder();
|
||||
|
||||
String[] splitAddr = address.split(",");
|
||||
int i = 0;
|
||||
for (int width = 0; width < 694; i++) {
|
||||
int splitSize = fm.stringWidth(splitAddr[i]);
|
||||
if ((width + splitSize) < 694) {
|
||||
width += splitSize;
|
||||
addrLineOne.append(splitAddr[i]);
|
||||
addrLineOne.append(",");
|
||||
} else {
|
||||
addrLineOne.deleteCharAt(addrLineOne.length() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; i < splitAddr.length; i++) {
|
||||
addrLineTwo.append(splitAddr[i]);
|
||||
addrLineTwo.append(",");
|
||||
}
|
||||
addrLineTwo.deleteCharAt(addrLineTwo.length() - 1);
|
||||
|
||||
g.setFont(ARIAL38I);
|
||||
g.drawString(addrLineOne.toString().trim(), 59, 491 - doubleNumOffset - longAddrOffset);
|
||||
g.drawString(addrLineTwo.toString().trim(), 59, 491 - doubleNumOffset);
|
||||
|
||||
String number = "";
|
||||
if (hasExtension && !hasCell) {
|
||||
|
Loading…
Reference in New Issue
Block a user