changing text size of SCNText - text

I'm trying to set the size of the font using this code:
func setupText(){
let text = SCNText(string: "textString", extrusionDepth: 4)
textNode.geometry = text
textNode.position = SCNVector3Make(0, -200, 5)
scene.rootNode.addChildNode(textNode)
text.alignmentMode = kCAAlignmentCenter
text.font = UIFont(name: "Helvatica", size: 30)
}
I'm changing the size argument but my text doesn't get any bigger or smaller. What am I doing wrong?

It doesn't work because the font isn't being set. The font isn't being set because you misspelled "Helvetica" as "Helvatica".

Changing the font size should work but maybe not as much as you would expect. This depends of the size of your 3d world.
Another way to scale up a 3d text is to scale its node:
textNode.scale = SCNVector3Make( scaleValue, scaleValue, scaleValue); //todo: make me swift

Related

Is it possible to use more than one custom font in an SVG?

I'm using the Univers LT 47 Condensed Light font in SVG. In some of the elements use the Univers LT 47 Condensed Bold font. The SVG is rendered correctly but when I print the SVG on a PDF none of the fonts are respected and a default font (Times) is used.
Later on, i figured out that with setting a (the?) font provider I'm able to use the standard font.
string fontUniverseLT47 = HttpContext.Current.Server.MapPath("fonts/lte50144.ttf"),
fontUniverseLT47Bold = HttpContext.Current.Server.MapPath("fonts/LT.ttf");
FontProvider provider = new FontProvider();
provider.AddFont(FontProgramFactory.CreateFont(fontUniverseLT47));
provider.AddFont(FontProgramFactory.CreateFont(fontUniverseLT47Bold));
SvgConverterProperties props = new SvgConverterProperties();
props.SetCharset("Windows-1252");
props.SetFontProvider(provider);
byte[] byteArray = Encoding.GetEncoding(1252).GetBytes(svg);
using (MemoryStream ms = new MemoryStream(byteArray))
{
Image image = SvgConverter.ConvertToImage(ms, pdf, props);
image.SetPageNumber(pageNumber);
image.SetFixedPosition(llx, lly);
image.ScaleToFit(width, height);
doc.Add(image);
}
But now I'd like to use the bold font which cannot be set in CSS with font-weight : bold as it's a different PdfFont.
Is there a way how I can use the second, bold font in the SVG?

How to find bit length of text with specific font and font size

I'm developing NativeScript JavaScript code to create dynamic text marker for maps. I have the code working that creates a marker for a specific string. My next step is to take any given string, determine its height and width in bits, and create the marker sized to contain the text.
My problem is finding the size of the text, given the text string itself, the font size, and the font family.
It looks like getMeasuredWidth could work, except that the string must already be loaded on a page before that function will return a value. In my case, I simply need to compute the size; the text won't otherwise appear as such on a page (the text in the marker becomes an image).
Is there a way to do this?
var bmp = BitmapFactory.create(200);
bmp.dispose(function (b) {
try {
b.drawRect(
"100,34", // size
'0,0', // upper-left coordinate
KnownColors.Black, // border color
KnownColors.Cornsilk // fill color
);
b.writeText(
"Parking",
"2,25",
{ color: KnownColors.Black, size: 8, name: 'fontawesome-webfont', });
...
In the code above, the width of "100" of the bounding rectangle actually represents the bit width of "Parking" with a small amount of padding. What I want to does calculate the rectangle's height and width and not hard-code it.
Try this, finding label size without adding it to Page upon button click
export function onFindButtonTap(args: EventData) {
const button = <any>args.object;
const label = new Label();
label.text = "Hello, found my size?"
label.fontSize = 20;
(<any>label)._setupAsRootView(button._context);
label.onLoaded();
label.measure(0, 0);
console.log(`Width : ${label.getMeasuredWidth()} x Height : ${label.getMeasuredHeight()}`);
}
Playground Sample
Note: I didn't get a chance to test it with iOS yet, let me know if you hit any issues.

Label font size

I want add to stage a label with specified font size.
val label = Label("label", Skin(Gdx.files.internal("uiskin.json")))
label.height = 20f
stage.addActor(label)
Changing label.height does not works, label is shown with some default size.
So the question is how to set label font size?
You can do only:
label.setFontScale(5.0f)
Also, you can specify font size in font file. It's the only way.
Try either setSize label.setSize(width, height) or setScale label.setScale(xyScaleFactor)

Extendscript: How to check whether text content overflows the containing rectangle

I am using Extendscript for Photoshop CS5 to change the text of a text layer. Is there a way of checking whether the text fits e.g. by checking whether it overflows after changing the content?
I created a solution that works perfectly fine :). Maybe someone else can use it as well. Let me know if it works for you too!
function scaleTextToFitBox(textLayer) {
var fitInsideBoxDimensions = getLayerDimensions(textLayer);
while(fitInsideBoxDimensions.height < getRealTextLayerDimensions(textLayer).height) {
var fontSize = parseInt(textLayer.textItem.size);
textLayer.textItem.size = new UnitValue(fontSize * 0.95, "px");
}
}
function getRealTextLayerDimensions(textLayer) {
var textLayerCopy = textLayer.duplicate(activeDocument, ElementPlacement.INSIDE);
textLayerCopy.textItem.height = activeDocument.height;
textLayerCopy.rasterize(RasterizeType.TEXTCONTENTS);
var dimensions = getLayerDimensions(textLayerCopy);
textLayerCopy.remove();
return dimensions;
}
function getLayerDimensions(layer) {
return {
width: layer.bounds[2] - layer.bounds[0],
height: layer.bounds[3] - layer.bounds[1]
};
}
How to use / Explanation
Create a text layer that has a defined width and height.
You can change the text layers contents and then call scaleTextToFitBox(textLayer);
The function will change the text/font size until the text fits inside the box (so that no text is invisible)!
The script decreases the font size by 5% (* 0.95) each step until the texts fits inside the box. You can change the multiplier to achieve a more precise result or to increase performance.
I haven't found a way to do this directly. But I've used the following technique to determine the height I needed for a textbox (I wanted to keep the width constant) before.
expand the textbox's height well beyond what is needed to accommodate the text inside it.
duplicate the layer
rasterize the duplicate
measure the bounds of the rasterized layer.
adjust the bounds of the original text layer as needed
delete the rasterized duplicate
Totally roundabout - but it did work.

SKIA - Inaccurate value returned by measureText()

I have a problem measuring text using skia measureText() function.
The value returned is inaccurate.
SkPaint *skPaint = new SkPaint();
SkTypeface* myFont = SkTypeface::CreateFromName("Impact", SkTypeface::kNormal);
skPaint->setTypeface(myFont);
skPaint->setAntiAlias(true);
skPaint->setTextAlign(SkPaint::kLeft_Align);
skPaint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
skPaint->setTextSize(SkIntToScalar(120));
skPaint->setColor(0xff000001);
canvas->drawText(text, length, SkIntToScalar(x) , SkIntToScalar(y) , *skPaint);
SkScalar width = skPaint->measureText(text, length);
The width returned by measureText() is 451.
I checked the generated bitmap text via a photo editor app, the actual width is only 438.
Any thoughts on getting the accurate width of text in SKIA?
Thank you!
I believe what you are trying to match will come from "bounds"
SkRect bounds;
SkScalar textWidth = paint.measureText("some", 4, &bounds);
which is a minimum rectangle to fit a given text, whereas textWidth is slightly larger than that.
I faced this issue too. Dont know why exactly it happens, maybe because of kerning differences, but i came to this:
SizeF RenderTextAndroid::GetStringSizeF() {
UpdateFont();
const base::string16& text = GetLayoutText();
std::vector<SkScalar> widths(text.length());
paint_.getTextWidths(text.c_str(), GetStrByteLen(text), &widths[0], NULL);
return SizeF(std::accumulate(widths.begin(), widths.end(), 0),
font_metrics_.fBottom - font_metrics_.fTop);
}
Where UpdateFont just sets new parameters to SkPaint

Resources