|
|
@ -9,6 +9,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.fr.design.gui.syntax.print; |
|
|
|
package com.fr.design.gui.syntax.print; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.text.BadLocationException; |
|
|
|
import javax.swing.text.BadLocationException; |
|
|
|
import javax.swing.text.Document; |
|
|
|
import javax.swing.text.Document; |
|
|
|
import javax.swing.text.Element; |
|
|
|
import javax.swing.text.Element; |
|
|
@ -62,8 +64,8 @@ public abstract class RPrintUtilities { |
|
|
|
private static int getLineBreakPoint(String line, final int maxCharsPerLine) { |
|
|
|
private static int getLineBreakPoint(String line, final int maxCharsPerLine) { |
|
|
|
|
|
|
|
|
|
|
|
int breakPoint = -1; |
|
|
|
int breakPoint = -1; |
|
|
|
for (int i=0; i<breakChars.length; i++) { |
|
|
|
for (char breakChar : breakChars) { |
|
|
|
int breakCharPos = line.lastIndexOf(breakChars[i], maxCharsPerLine-1); |
|
|
|
int breakCharPos = line.lastIndexOf(breakChar, maxCharsPerLine - 1); |
|
|
|
if (breakCharPos > breakPoint) |
|
|
|
if (breakCharPos > breakPoint) |
|
|
|
breakPoint = breakCharPos; |
|
|
|
breakPoint = breakCharPos; |
|
|
|
} |
|
|
|
} |
|
|
@ -147,11 +149,11 @@ public abstract class RPrintUtilities { |
|
|
|
int tabIndex = curLineString.indexOf('\t'); |
|
|
|
int tabIndex = curLineString.indexOf('\t'); |
|
|
|
while (tabIndex > -1) { |
|
|
|
while (tabIndex > -1) { |
|
|
|
int spacesNeeded = tabSizeInSpaces - (tabIndex % tabSizeInSpaces); |
|
|
|
int spacesNeeded = tabSizeInSpaces - (tabIndex % tabSizeInSpaces); |
|
|
|
String replacementString = ""; |
|
|
|
StringBuilder replacementString = new StringBuilder(); |
|
|
|
for (int i=0; i<spacesNeeded; i++) |
|
|
|
for (int i=0; i<spacesNeeded; i++) |
|
|
|
replacementString += ' '; |
|
|
|
replacementString.append(' '); |
|
|
|
// Note that "\t" is actually a regex for this method.
|
|
|
|
// Note that "\t" is actually a regex for this method.
|
|
|
|
curLineString = curLineString.replaceFirst("\t", replacementString); |
|
|
|
curLineString = curLineString.replaceFirst("\t", replacementString.toString()); |
|
|
|
tabIndex = curLineString.indexOf('\t'); |
|
|
|
tabIndex = curLineString.indexOf('\t'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -385,7 +387,7 @@ public abstract class RPrintUtilities { |
|
|
|
doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset), |
|
|
|
doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset), |
|
|
|
currentLineSeg); |
|
|
|
currentLineSeg); |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
System.err.println("BadLocationException in print (where there shouldn't be one!): " + ble); |
|
|
|
FineLoggerFactory.getLogger().error("BadLocationException in print (where there shouldn't be one!): " + ble.getMessage()); |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -417,12 +419,12 @@ public abstract class RPrintUtilities { |
|
|
|
// currentPos will be the last position in the current text of a "line break character."
|
|
|
|
// currentPos will be the last position in the current text of a "line break character."
|
|
|
|
currentPos = -1; |
|
|
|
currentPos = -1; |
|
|
|
String currentLineString = currentLineSeg.toString(); |
|
|
|
String currentLineString = currentLineSeg.toString(); |
|
|
|
for (int i=0; i<breakChars.length; i++) { |
|
|
|
for (char breakChar : breakChars) { |
|
|
|
// "+1" below so we include the character on the line.
|
|
|
|
// "+1" below so we include the character on the line.
|
|
|
|
int pos = currentLineString.lastIndexOf(breakChars[i]) + 1; |
|
|
|
int pos = currentLineString.lastIndexOf(breakChar) + 1; |
|
|
|
//if (pos>-1 && pos>currentPos)
|
|
|
|
//if (pos>-1 && pos>currentPos)
|
|
|
|
// currentPos = pos;
|
|
|
|
// currentPos = pos;
|
|
|
|
if (pos>0 && pos>currentPos & pos!=currentLineString.length()) |
|
|
|
if (pos > 0 && pos > currentPos & pos != currentLineString.length()) |
|
|
|
currentPos = pos; |
|
|
|
currentPos = pos; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -440,7 +442,7 @@ public abstract class RPrintUtilities { |
|
|
|
try { |
|
|
|
try { |
|
|
|
doc.getText(currentLineStart+startingOffset, currentPos, currentLineSeg); |
|
|
|
doc.getText(currentLineStart+startingOffset, currentPos, currentLineSeg); |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
System.err.println(ble); |
|
|
|
FineLoggerFactory.getLogger().error(ble.getMessage()); |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
currentLineLengthInPixels = Utilities. |
|
|
|
currentLineLengthInPixels = Utilities. |
|
|
@ -453,12 +455,11 @@ public abstract class RPrintUtilities { |
|
|
|
try { |
|
|
|
try { |
|
|
|
doc.getText((currentLineStart+startingOffset), currentPos, currentLineSeg); |
|
|
|
doc.getText((currentLineStart+startingOffset), currentPos, currentLineSeg); |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
} catch (BadLocationException ble) { |
|
|
|
System.err.println("BadLocationException in print (a):"); |
|
|
|
FineLoggerFactory.getLogger().error("BadLocationException in print (a):" + "==> currentLineStart: " + currentLineStart + |
|
|
|
System.err.println("==> currentLineStart: " + currentLineStart + |
|
|
|
"; startingOffset: " + startingOffset + "; currentPos: " + currentPos + |
|
|
|
"; startingOffset: " + startingOffset + "; currentPos: " + currentPos); |
|
|
|
"==> Range: " + (currentLineStart+startingOffset) + " - " + |
|
|
|
System.err.println("==> Range: " + (currentLineStart+startingOffset) + " - " + |
|
|
|
|
|
|
|
(currentLineStart+startingOffset+currentPos)); |
|
|
|
(currentLineStart+startingOffset+currentPos)); |
|
|
|
ble.printStackTrace(); |
|
|
|
FineLoggerFactory.getLogger().error(ble.getMessage()); |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
return Printable.NO_SUCH_PAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -521,7 +522,8 @@ public abstract class RPrintUtilities { |
|
|
|
return x; |
|
|
|
return x; |
|
|
|
int tabSizeInPixels = tabSizeInSpaces * fm.charWidth(' '); |
|
|
|
int tabSizeInPixels = tabSizeInSpaces * fm.charWidth(' '); |
|
|
|
int ntabs = (((int) x) - xOffset) / tabSizeInPixels; |
|
|
|
int ntabs = (((int) x) - xOffset) / tabSizeInPixels; |
|
|
|
return xOffset + ((ntabs + 1) * tabSizeInPixels); |
|
|
|
float reFloat = xOffset + ((ntabs + 1) * tabSizeInPixels); |
|
|
|
|
|
|
|
return reFloat; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|