Java 8/JavaFX: Drawing text in a rectangle - text

Is there a way to bind text to a JavaFX shape (for my purposes, I want to use rectangles) the same way you could using Graphics2D's drawString in previous versions of Java?
You may be able to just use Graphics2D still; I just don't know how to implement it.
Note: What isn't helpful is a way to place a Text object at the same x and y position as the shape on canvas. Rather, is there a way to actually write onto the Rectangle?

Related

LibGDX FreetypeFont in 3D

Is there a proper way to use GDX FreeTypeFont in 3D?
I'm not trying to rotate the text, but I do want the text to go behind 3D objects if the object's center is in front of the text.
Any ideas on how to do this?
Is there somehow a way to attach a Bitmap to a ModelInstance or something, so I can pass it into a ModelBatch?
Thanks
One way would be to use a Decal and DecalBatch (which are sorted in 3D space). Your can draw the BitmapFont to a Pixmap and then draw that on a decal. You can use the same approach to create a TextureRegion and attach it to a 3D ModelInstance, but I think the Decal way is a little easier.

Paperjs write text

I'm trying to understand how Paperjs works and I would like to know if it's possible to write text vectors, if yes how?
I tried Raphael.js before this, and I was almost satisfied with it but it seems that Paperjs is more (cross)browser compliant for some reasons, right?
Some examples would be nice!
Thanks for your answers.
Yes, it is definitely possible to create texts in paper.js.
var awesometext = new paper.PointText();
awesometext.content='awesome';
paper is better than raphael because its canvas based. Canvas is better supported on mobiles/tabs and hence the advantage of paperjs. However, since canvas is just a bitmap implementation, zooming will make canvas renderings not so good compared to svg renderings like in raphael.
So, it depends on what your priorities are for your application..
Paperjs handles text-scaling well, but it uses canvas' native methods to render the characters, so you can't access the vector data once they're drawn. But I imagine you'd only want vector characters to manipulate their shape, for example, morphing one letter into another, or creating a font editor.
If you just want hi res text then paperjs can do that no problem... or you could just set a bigger font size.
If you want to render text as vectors in paperjs, have a look at https://nodebox.github.io/opentype.js/

How do I draw a dot or a point in visual c++ and write next to it?

I want to draw a thick point or a dot in the client area of an mfc alpplication. Is there a function to do so? Alternatively I could even draw an extremely small circle and fill it with a colour to make it appear as a dot- but again how do I fill an object? especially a curved one?
Then I also want to put some text next to it- so what function could i use to "write" in the client area?
GetDC()->SetPixel(x, y, RGB(1,2,3))
Where GetDC() will return the current CWnd's device context, (x,y) are the coordinates, and RGB() is the red/greed/blue color.
Look at GetDC()->Ellipse() for a circle, etc. and GetDC()->TextOut() for displaying text.
It would be good to become familiar with device contexts in general, see:
MFC CDC Members

What is the proper way of drawing label in OpenGL Viewport?

I have a multiviewport OpenGL modeler application. It has three different viewports : perspective, front and top. Now I want to paint a label for each viewport and not succeeding in doing it.
What is the best way to print a label for each different perspective?
EDITED : The result
Here is the result of my attempt:
I don't understand why the perspective viewport label got scrambled like that. And, Actually I want to draw it in the upper left corner. How do I accomplished this, because I think it want 3D coordinate... is that right? Here is my code of drawing the label
glColor3f(1,0,0);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glRasterPos2f(0,0);
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen("Perspective"), GL_UNSIGNED_BYTE, "Perspective"); // Draws The Display List Textstrlen(label)
glPopAttrib();
I use the code from here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
thanks
For each viewport switch into a projection that allows you to supply "viewport space" coordinates, disable depth testing (glDisable(GL_DEPTH_TEST)) and depth writes (glDepthMask(GL_FALSE)) and draw the text using one of the methods used to draw text in OpenGL (texture mapped fonts, rendering the full text into a texture drawing that one, draw glyphs as actual geometry).
Along with #datenwolf's excellent answer, I'd add just one bit of advice: rather than drawing the label in the viewport, it's usually easier (and often looks better) to draw the label just outside the viewport. This avoids the label covering anything in the viewport, and makes it easy to get nice, cleanly anti-aliased text (which you can normally do in OpenGL as well, but it's more difficult).
If you decide you need to draw the text inside the viewport anyway, I'll add just one minor detail to what #datenwolf said: since you generally do want your text anti-aliased (even if the rest of the picture isn't) you generally want to draw the label after all the other geometry of the picture itself. If you haven't turned on anti-aliasing otherwise, you generally will want to turn it on for drawing the text.

resize and draggable the group of the SVG element

I am working on a SVG application and now want to let a user resize an object using draggable corners, very much like in SVG-edit (http://svg-edit.googlecode.com/svn/trunk/editor/svg-editor.html).
The functionality should work as follows: The user selects an SVG object, drags it to the main ‘canvas’ and once on the ‘canvas’, four corners on the outside of the object appear, the user can drag on each of the corner points & drag to enlarge the object. The objects will be rectangular in shape and created using paths, not using the SVG ‘rect’ function.
Would anyone have any suggestions as to how this should be implemented?
Thanks in Advance
You could take a look at some existing open source implementations. svg-edit is one which you already mentioned.
To showcase a tool that I developed, I wrote a demo which implements this functionality. This which may serve as a simpler and more restrictive example than svg-edit, as it doesn't do too much other than allow you to draw rects and circles, and rotate/translate/scale them.
I have edited jquery to make rect draggable, recently put them in a g and lost this functionality. The g doesn't contain the position data.
Might be possible to bubble down to the children elements.

Resources