Unable To Add Custom Fonts To iOS 4.3 - ios4

I know this Question has been asked several times before, and I have tried all the steps mentioned but still it does not work for me :(
I have font file name "spyv3b.ttf". I added it to my project, added its name in info.plist file as "spyv3b.ttf". Also it is copied to Bundle Resource. I installed this font in font book and there it is named as "Spylord Bold". I checked in my project by:
NSLog(#"%#",[UIFont FontWithName:#"Spylord Bold" size:22]);
it is returning null. Can anyone tell me where can I be mistaken? Thanks a lot in advance for help.

It is quite easy but little tricky one. Follow the listed steps:
Add fonts .ttf files int your project under the head of "Resources"
Add all the font details in your project info.plist file.
Check your required font is available in Xcode font family with NSLog(#"%#",[UIFont familyNames]);
Output on console:
2012-08-12 07:49:27.278 Quiz[1134:c07] (
Thonburi,
"Snell Roundhand",
"Academy Engraved LET",
"Marker Felt",
"Geeza Pro",
"Arial Rounded MT Bold",
"Trebuchet MS",
Arial,
Marion,
"Gurmukhi MN",
"Malayalam Sangam MN",
"Bradley Hand",
"Kannada Sangam MN",
"Bodoni 72 Oldstyle",
Cochin,
"Sinhala Sangam MN",
"Hiragino Kaku Gothic ProN",
Tahoma,
Papyrus,
Verdana,
"Zapf Dingbats",
Courier,
"Hoefler Text",
"Euphemia UCAS",
Helvetica,
"Hiragino Mincho ProN",
"Bodoni Ornaments",
"Apple Color Emoji",
Optima,
"Gujarati Sangam MN",
"Devanagari Sangam MN",
"Times New Roman",
Kailasa,
"Telugu Sangam MN",
"Heiti SC",
Futura,
"Bodoni 72",
Baskerville,
"Chalkboard SE",
"Heiti TC",
Copperplate,
"Party LET",
"American Typewriter",
AppleGothic,
"Bangla Sangam MN",
Noteworthy,
Zapfino,
"Tamil Sangam MN",
"DB LCD Temp",
"Arial Hebrew",
Chalkduster,
Georgia,
"Helvetica Neue",
"Gill Sans",
Palatino,
"Courier New",
"Oriya Sangam MN",
Didot,
"Bodoni 72 Smallcaps"
)
Check the exact name of your font in the font-family with NSLog(#"%#",[UIFont fontNamesForFamilyName:#"Tahoma"]);
Output on console:
2012-08-12 07:49:27.280 Quiz[1134:c07] (
"Tahoma-Bold"
)
Use the font with the name shown after NSLog(#"%#",[UIFont fontNamesForFamilyName:#"Tahoma"]);
lblQuizName.font = [UIFont fontWithName:#"Tahoma-Bold" size:64.0];
Happy Coding :)

I had a very weird problem - the one i guess no one will ever have.... My every step from start to end was OK.The problem was due to the presence of two app-Info.plist files...! I don't know when did I added the second one. After deletion of one plist file, when i still didn't made it, I created new project, added my previous project files to it and repeated all the steps for adding custom fonts.
Now everything is fine :)

Related

Tabulator table: Change font

I'm trying to use the Tabulator table. Changing theme (including different .css), I get new background and foreground colors but the font is always times new roman. How do I change it ?
Use it like this:
.tabulator {
font-family: "Courier New";
}

Drawing strings with slick2d and TTF

I've been experimenting with String printing in LWJGL using slickutils. Generally when browsing the web I found two approaches to this. First being bitmaps where you have an entire alphabet and print each letter as a Texture, the other being using TrueTypeFonts and the truetypefont.drawString(20f,20f,"LWJGL String Test", Color.green) method.
However, most of the literature I found was a few years old. What is the right way to do this at the current time?
At the moment I'm using the TrueTypeFont method, however my result confuses me.
//It doesn't matter which Font I try to load, I get the same green bar.
//I think it has something to do with not finding the Fonts?
Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
TrueTypeFont font = new TrueTypeFont(awtFont, true);
font.drawString(20f, 20f, "LWJGL TEST STRING",Color.green);
I've also copied an example from the internet and get the same result(just a bar).
Tried googling but couldn't find any fixes.
TrueTypeFont is deprecated. Use UnicodeFont instead.
Check this:
// Create a font with the size of 20, and not bold or italic.
Unicode font = new UnicodeFont("res/font.ttf", 20, false, false);
font.addAsciiGlyphs();
font.getEffects().add(new ColorEffect());
font.loadGlyphs();
g.setFont(font);
g.drawString("Shit example", 100, 100);

SVG Text bounding box is different from browser to browser when using #font-face?

I am trying to place an SVG Text-element according to the width and height of the text by getting the bounding box using the getBBox() method.
If the text is using a websafe font, this works reasonably well across different browsers, but if the text is styled using #font-face and a custom webfont, then the width of the text is returned incorrectly in Firefox (Mac) and Safari (iOS).
It works perfectly in both Safari (Mac) and Chrome (Mac).
If the gray box has the same width as the text, then it works in that browser.
Does anybody have an idea on how to get the correct width of the text bounding box in all browsers?
The browser is calculating the bounding box before it has finished loading/applying #font-face, assuming you don't need IE, you can wrap your BBox calculation function inside a document.fonts.ready promise...
document.fonts.ready.then(() => const bbox = textEl.getBBox());
Here is an example at work that exhibits the problem and the fix:
const xmlns = "http://www.w3.org/2000/svg";
const correct = document.getElementById("correct");
const incorrect = document.getElementById("incorrect");
visualizeBBox(incorrect);
document.fonts.ready.then(()=> visualizeBBox(correct));
function visualizeBBox(el){
const bbox = el.getBBox();
const rect = document.createElementNS(xmlns, "rect");
for (prop in bbox) rect.setAttribute(prop, bbox[prop]);
document.querySelector("svg").appendChild(rect);
}
svg text {
font-family: 'Diplomata SC', serif;
}
svg rect {
stroke: red;
fill: none;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Diplomata+SC&display=swap" rel="stylesheet">
<svg xmlns="https://www.w3.org/2000/svg" width="600" height="400">
<text x="0" y="40" font-size="24" id="correct">Correct dimensions</text>
<text y="100" font-size="24" id="incorrect">Incorrect dimensions</text>
<svg>
Today I ran into similar issue. Duopixel is right that getBBox() might return momental metric which may be unexpected because external font hasn't been loaded yet and some standard font is used instead.
The problem in WebKit (tested in Chrome 24.0.1312.52 and 26.0.1389.0 canary) is that the browser defers external font loading until it is first effectively used anywhere on the page. So even if you wait for onreadystatechange to become "complete" you are not guaranteed to have font metrics ready when calling getBBox() - you may still be the first one rendering a text styled with external font, inserting it into the document and immediately calling getBBox() on it (my case).
My workaround instead of calling mySVGInitCode() directly I do:
$("body").append(
$("<div/>")
.attr("class", "force-external-font-loading")
.attr("style", "font-family: \"xkcd\";visibility:hidden;position:absolute")
.text("x")
);
setTimeout(function(){ mySVGInitCode() }, 100); // 100ms is just arbitrary waiting time which should be sufficient for fetching the external font on a fast network, anyone has a better solution?
As you can see I dynamically insert absolutely positioned styled piece of text to force external font loading (visibility:hidden is important here instead of display:none). Then I wait some time before I execute my SVG code which could potentially render something and then immediately ask for metrics.

GridLayout+ScrollArea widget position after size change

I have a scrollArea with a gridlayout inside it, and i add QLabels to it with images. When the application starts it works fine and displays the labels correctly:
Note: i calculate how many labels fit on the current layout space.
If i maximize it works fine too:
But when i hit restore something weird happens:
You can see that only 6 labels are added (the same as in the first Screen shot) but here they are all positioned overlapping each other.
This is the initialization code for the ScrollArea and the Layout:
self.scrollArea = QtGui.QScrollArea(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.scrollArea.sizePolicy().hasHeightForWidth())
self.scrollArea.setSizePolicy(sizePolicy)
self.scrollArea.setAutoFillBackground(True)
self.scrollArea.setStyleSheet(_fromUtf8("border: 1px solid blue"))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.gridLayoutWidget = QtGui.QWidget()
self.gridLayoutWidget.setGeometry(QtCore.QRect(0, 0, 667, 551))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.gridLayoutWidget.sizePolicy().hasHeightForWidth())
self.gridLayoutWidget.setSizePolicy(sizePolicy)
self.gridLayoutWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.gridLayoutWidget.setAutoFillBackground(True)
self.gridLayoutWidget.setStyleSheet(_fromUtf8("border: 1px solid red"))
self.gridLayoutWidget.setObjectName(_fromUtf8("gridLayoutWidget"))
self.scrollArea.setWidget(self.gridLayoutWidget)
So thanks to #pyqt on freenode (shout out to Avaris) i now know what the problem is. It seems to be a bug in QGridLayout.
When we maximize the window QGridLayout ends up with 12 columns, when we do a restore even though every item is removed the layout still assumes 12 columns, so in picture 3 it is displaying 6 images but thinks it needs to display 12 so it just overlaps the other ones.

canvas draw text problem

If I execute the following code the text is shown bad (it seems not aliased) and not right aligned
why?
context.textBaseline = "top";
context.textAlign = "right";
context.fillStyle = "#F00";
context.font = "italic 30tpx sans-serif";
context.fillText("Lorem ipsum dolor sit amet", 50, 50);
I'm using FF 3.6...
I think Firefox doesn't know what you mean by "30tpx" and is ignoring your style. Also if you align right most of the text will be off the left of the screen -- maybe you mean to align right? Try this
contexto.textAlign = "left";
contexto.fillStyle = "#F00";
contexto.font = "italic 30px sans-serif";
When you align right it draws the text from right to left, with the text ending at the x coordinate.
I you look at this example you can see how the different text align settings draw text in relation to the x coordinate. I've included you code as well.

Resources