Skip to content

Ghidra is a software reverse engineering (SRE) framework

changes per review

ghidravore397a073bf65d
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
index 76183735f8..0d4317b0f5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
@@ -376,7 +376,7 @@ public class CodeBrowserClipboardProvider extends ByteCopier
try {
TextLayoutGraphics g = new TextLayoutGraphics();
- Rectangle rect = new Rectangle(2048, 2048);
+ Rectangle rect = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE);
AddressRangeIterator rangeItr = addressSet.getAddressRanges();
while (rangeItr.hasNext()) {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/VerticalLayoutTextField.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/VerticalLayoutTextField.java
index b13e483844..db4ff1b168 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/VerticalLayoutTextField.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/VerticalLayoutTextField.java
@@ -208,7 +208,8 @@ public class VerticalLayoutTextField implements TextField {
@Override
public void paint(JComponent c, Graphics g, PaintContext context,
- Rectangle clip, FieldBackgroundColorManager colorManager, RowColLocation cursorLoc, int rowHeight) {
+ Rectangle clip, FieldBackgroundColorManager colorManager, RowColLocation cursorLoc,
+ int rowHeight) {
if (context.isPrinting()) {
print(g, context);
return;
@@ -224,48 +225,61 @@ public class VerticalLayoutTextField implements TextField {
Highlight[] highlights = hlFactory.getHighlights(this, getText(), cursorTextOffset);
int columns = 0;
int n = subFields.size();
+
+ // the graphics have been translated such that the first line of text's base line is
+ // at y=0 (So if we are not clipped, we will drawing from negative the fonts height above
+ // the baseline (-heightAbove) to rowHeight -heightAbove
+ int myStartY = -heightAbove;
+ int myEndY = myStartY + rowHeight;
+ int clipStartY = clip.y;
+ int clipEndY = clip.y + clip.height;
+
Color fieldBackgroundColor = colorManager.getBackgroundColor();
if (fieldBackgroundColor != null) {
g.setColor(fieldBackgroundColor);
// restrict background rectangle to clipping rectangle
- int startY = Math.max(-heightAbove, clip.y);
- int clippedHeight = Math.min(rowHeight - (startY + heightAbove), clip.height);
+ int startY = Math.max(myStartY, clipStartY);
+ int endY = Math.min(myEndY, clipEndY);
+ int clippedHeight = endY - startY;
g.fillRect(startX, startY, width, clippedHeight);
}
+
+ int startY = myStartY;
int translatedY = 0;
+
for (int i = 0; i < n; i++) {
- ClippingTextField clippingField = (ClippingTextField) subFields.get(i);
- int subFieldHeight = clippingField.getHeight();
- int startY = translatedY - heightAbove;
-
- // if this line is totally above the clip, skip it, but still must translate for next line
- if (startY + subFieldHeight < clip.y) {
- g.translate(0, subFieldHeight);
- translatedY += subFieldHeight;
- continue;
- }
+ ClippingTextField subField = (ClippingTextField) subFields.get(i);
+ int subFieldHeight = subField.getHeight();
+ int endY = startY + subFieldHeight;
- // if this line is totally below clip region, we are done
- if (startY > clip.y + clip.height) {
+ // if past clipping region we are done
+ if (startY > clipEndY) {
break;
}
- // translate the highlights
- for (Highlight highlight : highlights) {
- highlight.setOffset(-columns);
- }
- clippingField.paintSelection(g, colorManager, i, rowHeight);
- clippingField.paintHighlights(g, highlights);
- clippingField.paintText(c, g, context);
- if (cursorRow == i) {
- clippingField.paintCursor(g, context.getCursorColor(), cursorLoc);
+ // if any part of the line is in the clip region, draw it
+ if (endY >= clipStartY) {
+ // translate the highlights
+ for (Highlight highlight : highlights) {
+ highlight.setOffset(-columns);
+ }
+ subField.paintSelection(g, colorManager, i, rowHeight);
+ subField.paintHighlights(g, highlights);
+ subField.paintText(c, g, context);
+ if (cursorRow == i) {
+ subField.paintCursor(g, context.getCursorColor(), cursorLoc);
+ }
}
+ // translate for next row of text
+ startY += subFieldHeight;
g.translate(0, subFieldHeight);
translatedY += subFieldHeight;
- columns += clippingField.getText().length() + lineDelimiter.length();
+ columns += subField.getText().length() + lineDelimiter.length();
}
+
+ // restore the graphics to where it was when we started.
g.translate(0, -translatedY);
}