Skip to content

Commit 0776f83

Browse files
authored
Merge pull request #41 from bloodwurm/master
#17: Cardname Line Break: Ability to manually enter a line break
2 parents f94fb8b + cede9e2 commit 0776f83

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/legedit2/cardtype/ElementCardName.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,41 @@ private LineInformation createLineInformation(String text, Graphics2D g, FontMet
9494

9595
private List<LineInformation> prepareTextLines(String text, Graphics2D g, Font font, int xStart, int yStart)
9696
{
97+
///////////////////////////////////////////////////////////////
98+
/// Manually convert end lines so that calling split finds them
99+
if (text.length() > 1)
100+
{
101+
for (int i = 0; i < text.length() - 2; i++)
102+
{
103+
if ((text.charAt(i) == '\\') && (text.charAt(i+1) == 'N'))
104+
{
105+
text = text.substring(0,i) + '\n' + text.substring(i+2);
106+
}
107+
}
108+
}
109+
///////////////////////////////////////////////////////////////
110+
111+
///////////////////////////////////////////////////////////////
112+
/// Break the strings in regards to all the end lines manually entered by the user
113+
String[] linesToProcess = text.split("\n");
114+
if (linesToProcess.length > 1)
115+
{
116+
List<LineInformation> linesToReturn = new ArrayList<LineInformation>();
117+
for (String line : linesToProcess)
118+
{
119+
linesToReturn.addAll(prepareTextLines(line, g, font, xStart, yStart));
120+
LineInformation lastLine = linesToReturn.get(linesToReturn.size()-1);
121+
yStart = lastLine.drawYPosition + lastLine.lineThickness;
122+
}
123+
return linesToReturn;
124+
}
125+
///////////////////////////////////////////////////////////////
126+
97127
g.setFont(font);
98128
FontMetrics metrics = g.getFontMetrics(font);
99129

100130
List<LineInformation> lines = new ArrayList<LineInformation>();
101-
//String tmpText = text.replaceAll("\\N", " ");
102-
//Boolean mustBreak = !text.contentEquals(tmpText);
103-
104-
if (/*!mustBreak && */getScreenStartingXPositionForString(/*tmpText*/text, metrics) > 0)
131+
if (getScreenStartingXPositionForString(text, metrics) > 0)
105132
{
106133
// no need to break anything up, it fits already
107134
lines.add(createLineInformation(text, g, metrics, xStart, yStart));
@@ -111,7 +138,7 @@ private List<LineInformation> prepareTextLines(String text, Graphics2D g, Font f
111138
// its too long, we need to break it down
112139
String newLine = "";
113140
int currentY = yStart;
114-
for (String word : /*tmpText*/text.split("\\s+"))
141+
for (String word : text.split("\\s+"))
115142
{
116143
String testLine = newLine + " " + word;
117144
if (getScreenStartingXPositionForString(testLine, metrics) > 0)
@@ -180,7 +207,7 @@ public void drawElement(Graphics2D g)
180207

181208
LineInformation lastLine = cardNameLines.isEmpty() ? null : cardNameLines.get(cardNameLines.size()-1);
182209
if (lastLine != null)
183-
currentYScaled += lastLine.lineThickness;
210+
currentYScaled = lastLine.drawYPosition;
184211

185212
int subnameGapScaled = getPercentage(subnameGap, getScale());
186213
if (subnameGapScaled >= 0 )
@@ -233,11 +260,11 @@ public void drawElement(Graphics2D g)
233260
int cardHeightScaled = getPercentage(cardHeight, getScale());
234261

235262
int bannerStart = 0;
236-
LineInformation firstLine = null;
263+
/*LineInformation firstLine = null;
237264
if (!cardNameLines.isEmpty())
238265
firstLine = cardNameLines.get(0);
239266
else if (subNameLines != null && !subNameLines.isEmpty())
240-
firstLine = subNameLines.get(0);
267+
firstLine = subNameLines.get(0);*/
241268
bannerStart = getPercentage(y, scale) - getPercentage(bannerExtraSizeTop, getScale());
242269

243270
int bannerEnd = 0;

0 commit comments

Comments
 (0)