2011-04-12
How to Use Custom Font in Titanium Studio
ちょっとやり方が特殊だったのでメモしておきます。
Titanium Studioのカスタムフォントの使い方:
1. http://www.fontsquirrel.com/などでフォントファイルを取得&解凍する。
2. 解凍したフォントファイルを/PATH/TO/PROJECT/Resources/に置く。
3. /PATH/TO/PROJECT/build/iPhone/Info.plistをコピーして、
4. /PATH/TO/PROJECT/にコピーしたInfo.plistをペーストする。
5. /PATH/TO/PROJECT/build/iPhone/以下のすべてのファイルを削除。
# 再ビルドでまた自動生成されるので気にしない。
# キャッシュをクリアするようなものです。
6. /PATH/TO/PROJECT/Info.plistを開く。
7. Add Itemをクリックし、”UIAppFonts”と入力。
8. 生成された"UIAppFonts"を右クリック->Value Type->Arrayを選択。
9. "UIAppFonts"の直前にある矢印アイコンをクリックし(フォーカスを移し)、その後同じアイコンを右クリック。
10. Add Rowを選択。
11. Item 0 が生成されるので、そのValueにフォントファイル名(e.g. "comic_zine_ot.otf")を入力。
12. Titanium Studio内の任意のコンポーネントでカスタムフォントを使用してみる。
例:
var customFontLabel = Ti.UI.createLabel(
{
text:"Custom Font Test",
top: 0,
font:{
fontSize:60,
fontFamily:"Comic Zine OT"
},
width:"auto",
textAlign:"center"
});
Titanium.UI.currentWindow.add(customFontLabel);
13. ビルド&実行してみて、うまく表示されれば成功です。
もしどこかでつまづいたら、次のサイトの動画を参考にすればよいかと思います。
Titanium Mobile: Displaying Custom Fonts
2011-04-11
Image-based Word List on iPhone with Titanium
昨日、偶然Titaniumに出会ってしまったので、即興でちょっとしたiPhoneアプリを作ってみました。flickr APIと自作API(例文検索API)を使ってますが、まぁ、あんまり期待したほど精度は良くないですね。しかもflickrのAPIはエラーが起きる始末w。
2011-04-10
Simple Tag Getter with lxml
所用で英文テキストが欲しかったので、lxmlで英文テキストを取ってくるスクリプトを作成。汎用性はまったく無いけど、とりあえず公開。
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
import sys
import urllib2
import lxml.html
def get_texts(url, tag):
try:
html = urllib2.urlopen(url).read()
except urllib2.HTTPError, e:
# If returned 404
#print e.read()
print "Can't access to the given URL."
return
root = lxml.html.fromstring(html)
anchors = root.xpath(tag)
text_list = []
for a in anchors:
text = lxml.html.tostring(a, method='text', encoding='utf-8')
#print text.strip('\t\n')
text_list.append(text.strip('\t\n'))
if not text_list:
text = "There are no tags in this page"
text_list.append(text)
return text_list
def create_xpath(tag, attr):
xpath = "//"
xpath += tag
if not attr == "":
xpath += "[@"
attr,value = attr.split("=")
xpath += attr
xpath += "=\"" + value + "\"]"
print "Created Xpath: " + xpath
return xpath
if __name__ == "__main__":
argv_len = len(sys.argv)
if not (argv_len == 3 or argv_len == 4):
print "Usage: python tag-getter.py URL TAG [ATTR]"
exit()
url = sys.argv[1].lower()
tag = sys.argv[2].lower()
if argv_len == 4:
attr = sys.argv[3].lower()
else:
attr = ""
xpath = create_xpath(tag, attr)
text_list = get_texts(url, xpath)
for t in text_list:
print t
Usage Example:
$ python tag-getter.py http://ebooks.adelaide.edu.au/c/carroll/lewis/alice/chapter1.html div class=dochead
Created Xpath: //div[@class="dochead"]
Alice in Wonderland, by Lewis Carroll
$ python tag-getter.py http://ebooks.adelaide.edu.au/c/carroll/lewis/alice/chapter1.html p
Created Xpath: //p
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice
she had peeped into the book her sister was reading, but it had no pictures or conversations in it, ‘and what is the use of
a book,’ thought Alice ‘without pictures or conversation?’
... 後略 ...
登録:
投稿 (Atom)

