itext multiline text on diagonal - c#-4.0

How i can add a multi-line text with itext on diagonal. meaning that if the text is to large for the first diagonal(the largest diagonal) it should move on the next or above diagonal and so one, to see all the text.
I already calculated the text angle for the diagonal and uses pdfcontentbyte to stamp but if my text is longer than the diagonal the rest of the words that don't fit on the diagonal it is not showed. I think i have to make something mathematical or i saw something with setsimplecolumn and chunks but this will show my text aligned horizontal.
If anyone has some ideas? Thanks, and of course need some code examples.

Don't shoot me if I'm wrong, but based on your description I think you're talking about 'irregular columns'. See http://itextpdf.com/examples/iia.php?id=67
This type of column isn't a rectangle. Basically, you define coordinates for the left border (can be a diagonal line) and coordinates for the right border. Then you pour text between these two lines.
If that's not what you meant, maybe you want to write text diagonally. In that case, you can still use ColumnText, but you need to change the coordinate system, so that the text isn't written in horizontal lines from left to right, but in diagonal lines from top to bottom (or bottom to top). Changing the coordinate system is done with the concatCTM method.

Related

How to use different colors for two rectangle and how to set distance between those two rectangles to zero?

I tried to give each rectangle a different color but unfortunately it did not work
I want the horizontal distance between those two rectangles to be zero
Here is what I want:
And here is the code and result: http://www.plantuml.com/plantuml/uml/rP9FIyD04CNl-ocMUXEAIMn198PYeE1PZu9iacawT3CRPgSjMlpkhfiISoXuyEISNjuly-V1hhmObdrdbTyXzOPDfviUzI999exVciOTaLgzCTR3X5IcthNizjJKpZhMmePyG42YrEG_XbeCjHRqIUbGiQLqJC0wNKRhMO31oNiFQqTInd5NbGqB8hveFexhpsWTQs2E6-2pdoJBzAvKwZDSzNFBBFVu0VTPLhoWXEyql_asYbSQG5hacx1MnsmFnoqA54W7z5XPc1-01MjZvo5mZTIEpM-X_ZZYMZy9T3eTLJQgszdfjnpPlyWngiK5jHnIhe2Qy3g_0000
but the most important thing to set the horizontal distance between these two rectangle to zero
It's not possible to do a 0 horizontal distance between two rectangles in PlantUML. You could do a table in Creole, but it won't look like your example, since the lines (rows) would be aligned in a table.
When I see your usage, I think you'd be better off using DOT (GraphViz). You can wrap DOT code in #startdot/#enddot in a PlantUML engine and it will draw the diagram. For example:
https://www.plantuml.com/plantuml/uml/TP1HIyCm58NVyol2_GDJvfj9MDkK8PIbn88FOm_PShN5q9OqeY3-TvDfApBMXzwSd2_dmDrCmVXWXq1iz-BDsD8f-BTJcEWdeV7h1ujqFxLcH3uwq_K1Fy8XMR_WckwTEQBZZB0cowkIvahBKdEu0LgKLJNBsn_vM6V5mswxs7KcvLdV0SstXQfKP7KfGSGIrkWqqa5IhPxYuns7DOWMdHjOhbVYVV3EibKZ_y0Oie37sOfJNqGkXMFNlu8udU5ar4et75hq2CBEjmAlX5tMFlydup-jHeZ3FVaY6-njtFWt
But, since you're writing lower-level DOT, you need to use that syntax to lay everything out. There is much more control, but it's no longer PlantUML.

Is there a simple algorithm that can find the envelope of several circles?

Given a number of points on a 2d surface and radiuses for these points I can easily paint circles for them. What I need is an algorithm that only paints the envelope (right word for what I am looking for?) or outer bound of these combined circles. Additionally a second set of circles can 'encroach' on these circles, resulting in a kind of 'border'.
Image of what I am looking for
A quick way to draw the outline of the union of the disks is to
fill all disks in yellow, then
fill all disks in white with a smaller radius.
This can be adapted to the "encroached" circles, provided you only fill the remaining portions of the disks. Unfortunately, in a general setting finding the remaining portions can be an uneasy geometric problem.
There is an alternative approach which can work in all cases:
fill an image with zeroes, then for all disks fill every pixel with the value of the distance to the circumference (maximum at the center), but only keep the highest value so far.
while you do this, fill a second image with the color of the disk that achieved that highest value. (Initialize the image with the background color.)
At the end of this process, the first image will represent a "terrain" made of intersecting cones; and for every point of the terrain, you will know the color.
finally, color the pixels that have a height smaller than the desired stroke width, using the color map.
You can do the drawing in two steps.
1) Draw the outline using the following method: For each point, draw a circle using your favorite circle-drawing method, but before drawing a pixel, ensure that it is not contained inside any other circle. Do this for every point and you will get your outline.
2) Draw the borders between different sets using the following method: For each pair of points from different sets, calculate the two intersection points of the circles. If there is an intersection, the border can be drawn as a segment joining these two points. However, you have to make two lines, one for circle A, and another for circle B. To draw the line for circle A, slightly offset the segment towards point A. Then, use your favorite line-drawing method, but before drawing a pixel, ensure that it is closer to point A that any other point of the opposite set. After drawing the line, repeat the process for circle B. Note that both segment are not guaranteed to be the same length since the asymmetry of the points of the different sets. It will, however, always form a closed shape when all outlines and borders are drawn.

How to find line segments intersecting a 2D viewport

In an infinite 2D space there are a set of lines, each line having a start and end point, and a time of creation: Line(p0, p1, t).
I want to find the lines that should be rendered in a top-down view of this 2D space (higher values of t show up closer to the viewport, not that it should be relevant.)
The intuitive answer is "check if either point is within the viewport coordinates," but this falls down when the points are further apart than the viewport area covers.
The other idea I had was using something like geohash, this would limit precision i.e. maximum zoom level of the viewport. The idea is enumerating the hashes of the cells intersected and storing them. This way querying is a matter of asking the right question.
Are there any ideal solutions? Has this been solved before?
I think you need to check two conditions: one that the rectangle of viewport overlaps the rectangle with corners (p0,p1) and the second that some corners of viewport rectangle are on the different sides of the whole line which contains line segment (p0,p1).
The task of finding rectangle overlap can be solved very effectively for very large number of rectangles using R-trees (http://en.wikipedia.org/wiki/R-tree).
The second task can be reduced to checking signs of the cross product of (p1-p0) x (corner_coordinate-p0)
(all three quantities taken as 3-d vectors with third coordinate equal to zero, the result will be vector along the perpendicular direction). There should be corners with the opposite sign of this cross product.

Finding a point clicked in a grid

Given this grid ( http://i.stack.imgur.com/Nz39I.jpg is a trapezium/trapezoid, not a square), how do you find the point clicked by the user? I.e. When the user clicks a point in the grid, it should return the coordinates like A1 or D5.
I am trying to write pseudo code for this and I am stuck. Can anyone help me? Thanks!
EDIT: I am still stuck... Does anyone know of any way to find the height of the grid?
If it is a true perspective projection, you can run the click-point through the inverse projection to find it's X,Z coordinates in the 3D world. That grid has regular spacing and you can use simple math to get the A1,D5,etc.
If it's just something you drew, then you'll have to compare the Y coordinates to the positions of the horizontal lines to figure out which row. Then you'll need to check its position (left/right) relative to the angled lines to get the column - for that, you'll need either coordinates of the end-points, or equations for the lines.
Yet another option is to store an identical image where each "square" is flood-filled with a different color. You then check the color of the pixel where the user clicked but in this alternate image. This method assumes that it's a fixed image and is the least flexible.
If you have the coordinates of end points of the grid lines then
Try using the inside-outside test for each grid line and find the position
Since this grid is just a 3D view of a 2D grid plane, there is a projective transform that transforms the coordinates on the grid into coordinates on the 2D plane. To find this transform, it is sufficient to mark 4 different points on the plane (say, the edges), assign them coordinates on the 2D plane and solve the resulting linear equation system.

VBA Bestfit position for datalabels on line chart

I was trying to make my own function to reposition data labels on line chart so they'll be in their best fit.
What does it mean best fit?
The data label wont be above the line itself (I took the higher angle of the point and put the data label in higher-angle/2 - so it will be in the middle of the higher angle) - I succeed to get the higher-angle but didn't succeed to get the position on graph (in pixels, relatively)
After u put the data label in the middle of the higher angle, you need to check with the other seriescollections, that the data label is not above one of other seriescollections line... - didn't reach this part.
and still I am not sure that's it...
Is anybody got something prepared? or someone wants to help me with it?
It is way over my level right now...
"Best fit" is a setting unique to pie chart data labels.
You have the option of positioning a line chart's data labels centered (directly on a point), as well as above, below, left of, and right of the point. You can also position the data label anywhere by changing the .left and .top properties of the label. Left and Top are in points with respect to the top left corner of the chart, so you will have to brush up on your algebra to fine tune label positioning.
As with all else involving charts, Keep It Simple is sound advice. Do you need to label everything, or can you get away with a few key labels?
So after some tries, I decided to ditch the idea since this's way too complicated for me.
What I can say is that I ditch it after I stepped up a little bit.
I could find the best position for each label only when there's one line.
I achieved it by calculating the bigger arc (assumed each point is the middle of a circle), and than put it in the middle of that arc.
to do it when you have more than one line, you have to consider the position of the points of the other line/s. Therefore it becomes much more complicated and this is the reason I decided to ditch it.

Resources