How to get the real height of a character (fontmetrics/graphics2d) - graphics2d

I am currently in need to get the real height of a character. I am aware of the functions like getDecsent(), getAscent(), ... but they only allow to get values regarding the hole font (in its context). I also tried the way using getStringBounds(), but that is the same story.
Like the title says, I am looking for a way to get the height value of just one char at a time.
For example 'N' is higher then 'n', 'I' just a little bit higher then 'i' and so on
Thanks for your time

Use this
Rectangle2D bounds = font.getStringBounds("put your string here", context);
//font can be set to whatever you want
//my suggestion is that you use the same font for both characters
//context is a object of FontRenderContext
System.out.println(bounds.getHeight());
//Instead of just printing it you could do this a second time and compare the 2 strings

Related

Using JSON.stringify but SSJS variant in XPages

for an application I am building an administration panel where a power user should be able to check the JSON structure of a selected object.
I would like to display the JSON object in a computed text field but display/format it nicely so it is better human readable, something similar as in pretty print.
Is there any function I could use in SSJS that results in something similar so I can use display json nicely in computed text / editable fields?
Use stringify's third parameter "space":
JSON.stringify(yourObject, null, ' ');
space
A String or Number object that's used to insert white
space into the output JSON string for readability purposes. If this is
a Number, it indicates the number of space characters to use as white
space; this number is capped at 10 if it's larger than that. Values
less than 1 indicate that no space should be used. If this is a
String, the string (or the first 10 characters of the string, if it's
longer than that) is used as white space. If this parameter is not
provided (or is null), no white space is used.
As XPages doesn't support JSON.stringify yet you can include JSON's definition as SSJS resource and use it.
As Knut points out, you can certainly add json2.js to XPages; I've previously used an implementation as Marky Roden's post outlines. This is probably the "safest" way of doing so, from the SSJS side of things.
It does ignore the included fromJson and toJson SSJS methods provided out of the box in XPages. While imperfect, they are functional, especially with the inclusion of Tommy Valand's fix snippet. Be advised, using Tommy's fix does wrap responses to ensure a proper JS object can be parsed by shoving an Array into an object with a values property for the array; so no direct pulling of an Array only.
Additionally, I believe it would be useful to point out that a bean, providing a convenience method or two as wrappers to use either the com.ibm.commons.util.io.json methods to abstract the conversion method, or switching in something like Google GSON, might be more powerful and unified, based on your style of development.
Knut, Eric, I came so far myself already.
function prettyPrint(id) {
var ugly = dojo.byId(id).value;
var obj = $.parseJSON( "[" + ugly + "]" );
var pretty = JSON.stringify(obj, undefined, 4);
dojo.byId(id).innerHTML = pretty;
}
and I call it e.g.
var name = x$('#{id:input-currentObjectCollectionFiltered}').attr("name");
prettyPrint(name);
I tried to make use the x$ function but was not able to make the ID dynamic there e.g.
var ugly = x$('#{id:" + id + "}').val();
not sure why. would be nicer if I just would call prettyPrint('input-currentObjectCollectionFiltered'); and the function would figure it out.
Instead of dojo.byId(id).value I tried:
var ugly=$("#" + id).val();
but things returns and undefined object: I thought jquery would be smarter to work with dynamic id's.
anyway stringify works just fine.

how do I change a lookup value to whole a number in ssrs?

How do I format a number with 2 decimal places to a whole number?
I used the Lookup function to get a result, but formatting decimal to whole number does not work for this value. I did Text box properties -> number -> whole number doesn't work for one of my value. Also customize number to #,### but its not changing anything.
How do I make this value display as a whole number?
You may be confusing how the number is displayed (which can be controlled using text box properties) and it's actual value. It sounds like the value returned from the lookup is not a number, it might be a string/text value instead which would explain why it was not affected by number formatting.
One option is to convert the value to an integer (whole number) in the lookup expression itself, using a function to convert the value: CInt()
For example if your expression currently looks something like this:
=Lookup(Fields!SomeField.Value, Fields!SomeDatasetField1.Value, Fields!SomeDatasetField2.Value, "SomeDataset")
then you can change it to:
=CInt(Lookup(Fields!SomeField.Value, Fields!SomeDatasetField1.Value, Fields!SomeDatasetField2.Value, "SomeDataset"))
Or if you want to keep the original value, but just change how it is displayed then convert to a decimal value instead:
=CDec(Lookup(Fields!SomeField.Value, Fields!SomeDatasetField1.Value, Fields!SomeDatasetField2.Value, "SomeDataset"))
and then use the text box formatting options to control the displayed format.

Use Textfield as a Variable Possible ? don't know

I am currently trying to do the following.
I have 2 Textfields, One is Taken from the Dataset (in the Pictures below i have used 400 as a plain number to make things more straight Forward).
now what i want is for one of them to be used as a Variable (not sure if this is the right Term)
i want the value that Text1 is given to automatically be divided from Text2.
Below you will see the Text1 (named Divide) Properties.
and this is Text2 where I am trying to use the Value of Text 1:
I Know everything about having to Convert The field into an Int or some Number, and everything,
what i don't get is how I am supposed to use Textfield1 in Textfield2 ?
Thanks for your Answers in Advance.
What programming language is that?
if it's C# you can do something like:
int x = int.Parse(Text2.Text);
this will convert the string of Text2 (Textfield) to an integer,
if it's java it would be like:
int x = Integer.parseInt(Text2.getText());
But if the user enter some character that isn't a number the problem will crash.
Here is the Answer, thanks again to Visakh16
=400/ReportItems!Divide.value
and here the link: Use Textfield as a Variable Possible ? - Social MSDN

How to calculate the words length in JTextPane

I am not mean the length of a string, I mean the words length.... for example...
As you can see that "This is a testing." is shorter than "THIS IS A TESTING.". But how can I get the different between these two words length, also, I would like to know the position of the text, do I enable to get these information from JTextPane? Thanks.
JTextComponent has methods to convert between model and view coordinates:
int docEnd = myTextPane.getDocument().getLength();
Rectangle r = myTextPane.modelToView(docEnd);

"." in query string messing up

I was working with queries that the data is being used for the meta description.
UPDATE cards SET meta_description = 'Amy\'s bugs address labels are printed on recycled label paper. Available in quantities of 30. Each label is 2.5 x 1 inch with rounded corners.' WHERE card_id = 'al007'
I have noticed though that the period after paper is shortening the meta description to just "Amy's bugs address labels are printed on recycled label paper." If I remove the period the entire description will show up then. Does anyone know how to solve this tiny dilemma?
I'm pretty sure that the issue is in whatever place you see the results. Most likely, there's a line feed after the period and your device does not support/show multi-line data. When you remove the period, you probably remove the carriage return as well.
Try escaping the period with '\'
Since you say, by removing period, the whole sentence is getting updated, I assume there is no problem with the column size.