Skip to content

Commit

Permalink
Node Y position computation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radkovo committed Nov 27, 2019
1 parent 8a896f9 commit 5712a22
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions src/main/java/org/fit/cssbox/pdf/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,53 +95,19 @@ public Vector<Node> getAllChildren()
}

/**
* Insert new Node to right place in the children Vector
* Inserts a new Node to right place in the children Vector
*/
public Node insertNewNode(ElementBox elem, TextBox text, ReplacedBox box, ListItemBox item, Node refToTreeEquivalent)
{

// gets the distance of new element from the top of the page
float y = 0;

if (elem != null)
{
y = elem.getAbsoluteContentY();
}
else if (text != null)
{
y = text.getAbsoluteContentY();
}
else if (box != null)
{
Rectangle cb = ((Box) box).getAbsoluteContentBounds();
y = cb.y;
}
else if (item != null)
{
y = item.getAbsoluteContentY();
}
Node newNode = new Node(this, elem, text, box, item, refToTreeEquivalent);

// goes through child node and inserts new node to right place
for (int x = 0; x < nodeChildren.size(); x++)
{

if (nodeChildren.elementAt(x).getElemY() > y)
{
nodeChildren.add(x, newNode);
return newNode;
}
}
nodeChildren.add(newNode);
return newNode;
final Node newNode = new Node(this, elem, text, box, item, refToTreeEquivalent);
return insertNewNode(newNode);
}

/**
* Insert new Node to right place in the children Vector
* Inserts a new Node to right place in the children Vector
*/
public Node insertNewNode(Node newChild)
{

if (newChild == null) return null;

// gets the distance of new element from the top of the page
Expand Down Expand Up @@ -189,7 +155,7 @@ else if (this.box != null)
/////////////////////////////////////////////////////////////////////

/**
* Returns the distance of stored ELEM/TEXT/BOX from top of the page
* Returns the distance of stored ELEM/TEXT/BOX/ITEM from top of the page
*/
public float getElemY()
{
Expand All @@ -207,11 +173,15 @@ else if (this.box != null)
Rectangle cb = ((Box) box).getAbsoluteContentBounds();
return cb.y;
}
else if (this.item != null)
{
return item.getAbsoluteContentY();
}
return -1;
}

/**
* Returns the distance of stored ELEM/TEXT/BOX from left side of the page
* Returns the distance of stored ELEM/TEXT/BOX/ITEM from left side of the page
*/
public float getElemX()
{
Expand All @@ -229,6 +199,10 @@ else if (this.box != null)
Rectangle cb = ((Box) box).getAbsoluteContentBounds();
return cb.x;
}
else if (this.item != null)
{
return item.getAbsoluteContentX();
}
return -1;
}

Expand Down Expand Up @@ -375,4 +349,19 @@ public float getPlusHeight()
{
return this.plusHeight;
}

@Override
public String toString()
{
String type;
String info;
if (isBox()) { type = "box"; info = getBox().toString(); }
else if (isText()) { type = "text"; info = getText().toString(); }
else if (isElem()) { type = "elem"; info = getElem().toString(); }
else if (isItem()) { type = "item"; info = getItem().toString(); }
else { type = "?"; info = ""; }

return type + " [" + info + "]";
}

}

0 comments on commit 5712a22

Please sign in to comment.