Add double lines in the middle of another svg line - svg

so I have a drawing program and I need to implement a "broken line", it is an SVG line with two another lines in the middle of this line, these two line needs to cross perpendicularly to the principal line, maybe this picture can help me to explain the problem:
This line can be drawn in any angle that the user choose
I don't really understand svg's so I'm having a lot of trouble implementing this.
Thank you

So I discovered one way to implement that using polylines and calculating the middle of the source and target coordinates, so when it changes I change the middle point too. After that, I created a marker-mid with the double lines.

Related

SVG path data format differences

I'm working on a project where I need to parse svg path data.
Right now we're loading an svg, looking for the path tag, and pulling out it's d attribute.
For some of the artwork we'll get path data that is made up of coordinates which we can translate into the data types we need. E.g.
But other times the d value is in a more g-code-esq format.
Like in this case I drew a rectangle, converted it to a compound path:
And when I export it and look at the svg I get a d value like this:
Which we can't easily parse for the project.
My questions are:
How do I read this second format? It doesn't seem to fit what I'm reading on MDN so I suspect there's some other documentation I need to refer to: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
For illustrator users, is there a way of changing the format when exporting?
I know that this seems like more of an art question than a programming question, but I'm trying to understand the underlying reasoning behind the svg data structure so I can better parse it.
Oh! Oh ok, I was 100% misunderstanding the path data that I was reading. I didn't realize that the delimiting information was based on the letter. My brain wanted some specific character as a delimiter like a comma or pipe.
So reading (and in some cases re-reading :| ) the documentation, when I see:
M753,315H435.27V165H753Z
I can read that as:
M753,315 Move to x,y coordinates x: 753 y:315
H435.27 Starting at the current location, draw a horizontal line to the absolute x coordinate of 435.27
V165 Starting at the current location, draw a vertical line to the absolute y coordinate of 165
H753 Starting at the current location, draw a horizontal line to the absolute x coordinate of 753
ZDraw a straight line to the initial point of this path to close the path. This doesn't necessarily mean a horizontal or vertical line, but the coincidence that we're at the same x coordinate that we started at means that if we draw a straight line we will get a vertical line to complete the rectangle
That seems right. Anything I missed or misunderstood?
Also, thank for all of the links. I appreciate the points :clap: :bows:

Trim VLA-OBJECTS Outside Circles automatically without selecting anything

what I want to do is to trim some polylines that are saved as VLA-OBJECTS, there is no problem on converting them into Entities, but what I graphically want is to trim my Image in the following way:
So as you can see I want to trim everything of the blue lines outside the red circles on the corners and I want to it automatically without selecting anything. For this purpose, I have stored the circle as a VLA-OBJECT, The blue polylines as independent VLA-OBJECTS, the centers of the circles, in fact everything on the first image is stored on memory as a VLA-OBJECT. So I was wondering if you can suggest any lisp routine to do it automatically?. I was thinking on using the Break command or the Extend command but I can not find a real solution. Many thanks in advance.
I have no time enought to prepare working sample code, but I may show You the way. I would try to make it in this way:
You can find intersections of circles and lines.
( vlax-invoke-method circle 'IntersectWith BlueLine acExtendNone )
break each blue line by this
(foreach line BlueLines
(command "_break" line pt pt ) ; where pt is point returned by IntersectWith
)
and the last step is to check if all entities created by _break are inside or outside circles.
You don't have easy access to entities created by _break. to get them, You may use (entlast) before command _break. and (entnext) after that .

How can I draw to an XY position in Emacs?

I wanted to allow the Emacs cursor to move around freely outside of actual text (similar to virtualedit=all in Vim).
"Oh," I thought, "I'll just keep track of a virtual cursor and draw it to the screen myself."
But it turns out the actual native C drawing routines (such as draw_glyphs) seem to refer back to the buffer contents to decide what to draw (I could be wrong though).
My next idea was to make a giant overlay of all spaces so I'd have complete freedom where to put stuff. But an overlay only goes over ranges of actual text, so again, this does not seem to give me what I'm looking for.
Is this a reasonable goal without hacking the C code?
I believe the writeable area of a window is intrinsically limited to the buffer with which it is associated, i.e. you have to draw in an area where buffer content exists.
(One example of this limitation is the impossibility of drawing a vertical guide line in the 80th column to help the user identify long lines; currently the best possible implementation of such a feature is to highlight the "overflow" of each too-long line.)
You can do the same as what artist-mode does without adding spaces to the buffer:
when trying to place the cursor after the end of the line, just use an overlay with an after-string property which adds the spaces in the display without modifying the buffer.
Have a look at "artist-mode" (M-xartist-modeRET) - it allows you to draw in Emacs.
From the function documentation: "Artist lets you draw lines, squares, rectangles and poly-lines, ellipses and circles with your mouse and/or keyboard."
You can look at popup.el from the auto-complete package, which can pop up tooltips and menus and such at any position, including positions outside the contents of the buffer. Maybe that will show you how you can do it.

'Slider Control' kind of controls in Cocos2d help

I am making a game in Cocos2d. I want there to be a dotted line that follows the user's finger. I want the line to be straight. The problem is, how do I check to see how many 'dots' will fit in the distance between the ball and where the user is touching? And make it follow in a STRAIGHT line between the ball's position and the finger's position? So here's a re-clarification:
The ball sits still on the left side of the screen, and is halfway up the screen. The user drags their finger, and a dotted line is drawn between the ball's position and the touch's position. I have a 'dot' image to be used, and I would like it to be used as the dots in the line. So it will have to recreate the sprite as many times as it will fit in the area between the two points. Please tell me if you want me to clarify further, Thanks!!
I would make a CCNode object called dottedLine or something.
The dot image would be a sprite that gets added as a child of the node (multiple times).
I would work out the path from ball to finger touch using Trigonometry/Pythagoras theorem.
For creating the line:
From point 0, the ball, i would add 15-20 pixels towards the touch point along the path, and place a dot, I'd repeat this until I reached the end of the line.
Every dot that was placed I would increment a counter, and set that number as the integer tag of that sprite for use in an update method.
Every time the cctouchesmoved method gets called, i'd call an update method on the dottedLine object.
This method would check the distance between the ball and touch point, divide it by the number of dots currently children of the object and remove or add any that are needed. Recreating the sprites every time you move your finger would be messy and wasteful, so reusing your dots and just setting them new positions as the path between ball and touch point changes would probably be best.
I'm not going to provide you code, i think i've explained more than enough of the working out for you to do some googling and work this out.

NSAttributedString: wrapping + truncation

I have a view that draws multicolored text inside UITableViewCell. To draw multicolored text I'm using NSAttributedString However, I would like to make it so that if the text is too long to fit into the view, the last visible line is truncated to display an ellipsis at its end.
Obviously this is very easy to do when drawing only a single line, as you can just set
kCTLineBreakByTruncatingTail for the line break mode of the paragraph style. The problem is that I want my text to wrap to fill the rectangle, and then only have the last line truncated with an ellipsis - setting the line break mode confines the whole text to one line.
Does anybody have any ideas of how I would go about this?
Many thanks in advance for any suggestions,
JC.
Create your CTFrame from your CTFrameSetter with the rectangle of your UITableViewCell. Then, you can get all the CTLines of your CTFrame and determine when they will cut off. To swap out the ellipsis, you could keep that drawn with a separate CTFrame and draw it over the overflowing text on the last line.
You can find working code here: https://stackoverflow.com/a/14612598/473067
It's a similar approach to what Heath suggested. But then all wrapped up in a shiny package.
Well, to activate text truncating in UILabel, you should re-set lineBreakMode parameter to NSLineBreakByTruncatingTail after setting attributedText.
textLabel.attributedText = attributedText;
textLabel.lineBreakMode = NSLineBreakByTruncatingTail;

Resources