I have a binding for a rectangle on an canvas like this:
xLeft.textProperty().bind(fieldCanvas.layoutXProperty().asString());
The value returned in the TextField is returned with one decimal place. Since I'm working with pixels, I'm trying to get rid of the DP i.e. display as an integer.
How can I format the DoubleProperty (layoutXProperty) to zero DP?
xLeft.textProperty().bind(fieldCanvas.layoutXProperty().asString("%.0f"));
Related
I have several memos with different font on QuickReport. Now I'd like to know the most bottom point for all (for set some shape below). How? If I calculate TextHeight for each and multiple by lines count (aMemo.ParentReport.TextHeight(aMemo.Font, 'W') * aMemo.Lines.Count), results are not correctly - QuickReport print lines like with strange height and position of my shape for some fonts are too high or too low.
Ok, I got it. TextHeight cannot be call from QuickReport, but from Printer.Canvas. Then divide it by Y-Resolution for printer, next divide by 254 and multiple by 96. Result will be round and this is real value of Height of text in TQRMemo. All values are not accessible before print from QuickReport. It's very "smart" to return not real values based on same properties like during printing by component (by TQuickRep.TextHeight method).
I have a question about datawindow type LABEL.
Customer want print label from position.
And PowerBuilder 11.5 have problem with rectangle object and worse with bitmap object.
More on images in link.
Any way to correct it?
a link[1]
You may conditionally display your bitmap by creating a computed field similar to this:
bitmap( if( typ_čárového_kódu = "EAN 128", "mamut.bmp", "" ) )
Don't forget to size the computed field with the same dimensions as mamut.bmp.
I have a NSAttributedString which is a "table" using NSTextTab stops where the first column is the KEY and the second column is the value
Like this:
| **KEY 1**|value1|
|**KEY TWO**|value2|
The font for the KEYS is different size/weight + it is all caps.
The rows align so that the bottoms of all the letters match up. I would like to nudge the values up vertically so that they appear to be vertically centered with the KEYS.
Is there any way to do this? This seems highly specialized, but from a design perspective I think it will look much better
I haven't tried it, but it seems like you should be able to use NSBaselineOffsetAttributeName for this. Here's what the docs say about it:
The value of this attribute is an NSNumber object containing a
floating point value indicating the character’s offset from the
baseline, in points. The default value is 0.
So you'll probably have to compute the number of points needed to move the values up -- I guess that'd be half the difference in font sizes between the keys and values. Then apply NSBaselineOffsetAttributeName with that number of points to the text for the values.
I have the codes on jsfiddle
http://jsfiddle.net/9qdBD/
I am able to plot out the axises and grid line, but when it comes to the actual line, I got parsing issue. Not sure why. I am probably missing something obvious. Here is the error I got.
Error: Problem parsing d="MNaN,1LNaN,8LNaN,2LNaN,10LNaN,3LNaN,20LNaN,90"
Here the updated, working jsFiddle
A couple of things were wrong:
For the x coordinates of the line you had
formatter(parser.parse(d.date))
First, calling formatter on the parsed date produces a String, which is not what you want for plotting values. You need quantitative values of date, so just parser.parse(d.date)
Next, you need to to convert each date to an x-position along the x-axis. You had created an x-scale (assigned to the var x in your code), which you're using to draw the axis, and you need to use that same scale to convert the dates to the said x-positions:
return x(parser.parse(d.date))
That fixes the x positions. Then you need to do a similar thing for converting your y values to y positions:
return y(d.total)
It's a TMemo, not that that should make any difference.
Googling suggests that I can use Canvas->TextWidth() but those are Delphi examples and BCB doesn't seem to offer this property.
I really want something analogous to memo->Font->Height for width.
I realize that not all fonts are fixed width, so a good estimate will do.
All that I need is to take the width of a TMemo in pixels and make a reasonable guess at how many characters of the current font it will hold.
Of course, if I really want to be lazy, I can just google for the average height/width ratio, since height is known. Remember, an approximation is good enough for me if it is tricky to get exact.
http://www.plainlanguagenetwork.org/type/utbo211.htm says, " A width to height ratio of 3:5 (0.6) is recommended for most applications"
Actually your google search is not entirely off. You do need access to a canvas object, or at least a handle to a DC object. In general when searching for help concerning VCL classes it often pays to search for delphi examples since these are more common.
Anyway to calculate the size of a string you could have a look at the TextExtent function, it is a function for the TCanvas class. Simply pass the character which width you want to test, and the return value will be a TSize construct. However there is also a TextWidth function, as well as a TextHeight function. You can use these as well. Actually these call the TextExtent internally.
You have to note one thing though, the functions use the current font of the TCanvas object, more specifically the font bound to the DC the canvas uses. So assign the font you wish to test with first, and then pass the character.
I have some old code that calculates the width of a string like this:
// This canvas could be the form canvas: canvas = Form1->Canvas or the
// memo canvas which will probably be what you want.
canvas->Font->Assign(fontToTest);
int textwidth = TextWidth(textToTest);
If you want more control of what to do, you can also do this using the Windows API, this is essentially what the VCL does for you, in that case the following example would look like this:
// This canvas could be the form canvas: canvas = Form1->Canvas
canvas->Font->Assign(fontToTest);
// The initial size, this is really important if we use wordwrapping. This is
// the text area of the memo control.
TRect rect = ClientRect;
// This is the font format we wish to calculate using, in this example our text
// will be left aligned, at the top of the rectangle.
fontformat = DT_LEFT | DT_TOP;
// Here we calculate the size of the text, both width and height are calculated
// and stored in the rect variable. Also note that we add the DT_CALCRECT to the
// fontformat variable, this makes DrawTextEx calculate the size of the text,
// without drawing it.
::DrawTextEx(canvas->handle,
textToTest.c_str(),
textToTest.Length(),
&rect,
fontformat | DT_CALCRECT,
NULL);
// The width is:
int width = rect.Width();
The fontformat is a parameter that specifies different options for how to align and layout the text, if you plan on drawing text it will be a good idea to check out the different possibilities it offers: DrawTextEx Function [1]
EDIT: Reading through your question again, it struck me that the function you might be searching for is: GetTextExtentExPoint Windows API documentation states the following about this function:
The GetTextExtentExPoint function
retrieves the number of characters in
a specified string that will fit
within a specified space and fills an
array with the text extent for each of
those characters. (A text extent is
the distance between the beginning of
the space and a character that will
fit in the space.) This information is
useful for word-wrapping calculations.
You can find more information about the GetTextExtentExPoint function here: GetTextExtentExPoint Function [2]
[1] http://msdn.microsoft.com/en-us/library/dd162499%28VS.85%29.aspx
[2] http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx
What you could do, if you have access to Win32 API functions, is create a RichEdit Window the same size as your TMemo window, place the text in the RichEdit window, send the EM_FORMATRANGE message to the window and from the result determine how many characters it will hold. Of course this method will work with multiple lines etc...