
Sphinxプロジェクト準備
source/conf.py 編集
extensions = extensions + [‘sphinx.ext.graphviz’,’rst2pdf.pdfbuilder’]
pdf_documents = [
(‘index’, u’social_media_tech’, u’Social Media Technology’, u’hdknr.com’),
]
pdf_stylesheets = [‘sphinx’,’kerning’,’a4’,’ja’]
pdf_extensions = [‘vectorpdf’]
default_dpi=94
font_path=”/usr/share/fonts/truetype/”とりあえず、default_dpi=94 を入れてみる。
スタイルシート
{
“styles” : [
[“base” , {
“wordWrap”: “CJK”
}]
]
}
MakefileにPDF追加
(social)hdknr@deblen2010:~/.ve/social/src/testdoc$ tail Makefile
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
pdf:
$(SPHINXBUILD) -b pdf $(ALLSPHINXOPTS) $(BUILDDIR)/pdf
@echo
@echo "Build finished. The PDF files are in $(BUILDDIR)/pdf."
source/index.rst だけ編集
(social)hdknr@deblen2010:~/.ve/social/src/testdoc$ vi source/index.rst
Welcome to test's documentation!
================================
Contents:
.. toctree::
:maxdepth: 2
.. image:: facebook_try.JPG
ビルド
(social)hdknr@deblen2010:~/.ve/social/src/testdoc$ make pdf
sphinx-build -b pdf -d build/doctrees source build/pdf
Running Sphinx v0.6.4
loading pickled environment... done
building [pdf]: targets for 1 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
processing social_media_tech... index
resolving references...
done
writing social_media_tech... [WARNING] image.py:338 Using image /home/hdknr/.ve/social/src/testdoc/source/facebook_try.JPG without specifying size.Calculating based on image size at 96dpi [near line UNKNOWN in file UNKNOWN]
[WARNING] image.py:399 image /home/hdknr/.ve/social/src/testdoc/source/facebook_try.JPG is too wide for the frame, rescaling
done
build succeeded.
Build finished. The PDF files are in build/pdf.
表示
Posted via email from 原宿工業大学 | Comment »
画像の扱い
画像を PDF に埋めこんでみます。
画像はなんでも良いですが、とりあえず Imaging-1.1.7.tar.gz の中の Images フォルダの中か、 http://hg.effbot.org/pil-2009-raclette/src/tip/Images/ から lena.gif、lena.png、lena.jpg、lena.ppm を取得します。
lena の画像が宗教的な理由や感情的な理由等で駄目な人は別の画像でも問題ありません。 PIL がサポートしているフォーマットに関しては PIL Handbook を参照してください。
sample.rst を以下のようにして、同様に PDF を生成します。
test ============ sample こんにちはこんにちは .. image:: Images/lena.gif .. image:: Images/lena.jpg .. image:: Images/lena.png .. image:: Images/lena.ppm以下のような WARNING が発生するかもしれません。
[WARNING] createpdf.py:377 Using image Images/lena.gif without specifying size.Calculating based on image size at 300dpi [near line 8 in file sample.rst]これは画像に表示サイズを指定していないため発生します。画像は通常ピクセル等でサイズを表現しますが、PDF では センチやインチといったサイズで処理する必要があります。
rst2pdf にて reST ファイルを PDF に変換する場合 DPI(dots-per-inch) の値を利用して変換します。
300 ピクセルの画像を 300 DPI で変換すると、1 インチで表示されます。300ピクセルの画像を 100DPI で変換すると 3インチになります。
画像に以下のようにサイズを指定するのが一番良い方法です。
.. image:: Images/lena.png :width: 3in実際の所、毎回画像のサイズを指定するのはなかなか難しいと思いますので、 WRNING が発生しても正常に画像が表示されるように DPI のデフォルト値を設定ファイルに記述して置くのが良いでしょう。
ディスプレイのサイズにもよりますが DPI は 72DPI か 94 DPI 程度にするとディスプレイで見ているサイズに近いサイズになるはずです。
rst2pdf の設定ファイルに以下を記述しておくと良いでしょう。
default_dpi=94さらなる画像サポートの追加
PIL では多くのフォーマットをサポートしていますが、 PIL でサポートされない形式もあります。
PIL でサポートされない代表的なファイルとしては、Postscript、EPS、SVG等が存在します。
UniConvertor をインストールするとベクターイメージを PDF に埋め込むことができます。
curl -O http://sk1project.org/downloads/uniconvertor/v1.1.4/uniconvertor-1.1.4.tar.gz tar xvfz uniconvertor-1.1.4.tar.gz cd UniConvertor-1.1.4 sudo python setup.py install mkdir ~/.uniconvertorベクターイメージを利用しないなら特に必要ありませんが、高品質な画像を PDF に埋め込みたい場合は必要になるでしょう。
Posted via web from 原宿工業大学 | Comment »
You have not informed bzr of your launchpad login. If you are attempting a
write operation and it fails, run “bzr launchpad-login YOUR_ID” and try
again.
bzr: ERROR: Unknown branch format: ‘Bazaar Branch Format 7 (needs bzr 1.6)\n launchpadにpublicキーの登録
(op)hdknr@deblen:~/.ve/op/src$ bzr launchpad-login hdknr (op)hdknr@deblen:~/.ve/op/src$ bzr branch lp:aafigure
The authenticity of host ‘bazaar.launchpad.net (91.189.90.11)’ can’t be
established.
RSA key fingerprint is 9d:38:3a:63:b1:d5:6f:c4:44:67:53:49:2e:ee:fc:89.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘bazaar.launchpad.net,91.189.90.11’ (RSA) to
the list of known hosts.
bzr: ERROR: Unknown repository format: ‘Bazaar
RepositoryFormatKnitPack6RichRoot (bzr 1.9)\n’
Posted via email from 原宿工業大学 | Comment »
django.contrib.markup で使えるmarkup
hdknr@deblen:~/.ve/djtweet/src/djcube/www/website$ grep def ../../../../lib/python2.5/site-packages/django/contrib/markup/templatetags/marku
def textile(value):
def markdown(value, arg=”):
def restructuredtext(value):
使えるマークアップ確認
»> import markdownTraceback (most recent call last):
File “<input>”, line 1, in <module>
ImportError: No module named markdown
»> import textile
Traceback (most recent call last):
File “<input>”, line 1, in <module>
ImportError: No module named textile
»> from docutils.core import publish_parts
»>
»> このvirtualenvではReSTのみ。
settings.pyに設定
INSTALLED_APPS = (‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.sites’,
‘django.contrib.admin’, #HDKNR
‘django.contrib.markup’, #HDKNR
試しにファイルを用意する
Sequence======== 1. (Guest) Submit form on a landing page.
————————————————————- Browser post(get) form to following URL :: http://{{cname}}/{{app}}/promocode/{{promotion_name}}/?code={{promotion_code}} 2. (Promo) Process the request
———————————————- 2.1. Search djcube.models.Promotion with {{promotion_name}} => `pr`.
2.2. Search djcube.models.PromotionCode with `pr` and {{promotion_code}}.
2.3. Insert a djcube.models.PromotionEntry. 2.3.1. md5 for UserAgent should be set to `ua`
2.3.2. Insert djcube.models.UserAgent with `ua` if not exists. 2.4. Update jcube.models.PromotionCode with incremented `current`.
2.4. Set-Cookie ‘p’ : djcube.models.Promotion.digest
‘e’ : djcube.models.PromotionEntry.digest 2.5. Execute {{ djcube.models.Promotion.ptype }}.py main() 2.5.1. finally return 302 and proper URL
testビューを用意
views.pyと同じディレクトリにreadme.rst を用意 from django.conf.urls.defaults import *from django import template
from django.http import HttpResponse
import os def test(request):
page = “”” {% load markup %}
<html>
<body>
{{ readme|restructuredtext}}
</body>
</html>
“”“
ctx = {
‘readme’: open(os.path.join( os.path.dirname(os.path.abspath(__file__)),’readme.rst’)).read(),
}
return HttpResponse( template.Template( page ).render( template.Context(ctx)))
表示
Include Directive
外部ファイルをインクルードする。 自分で定義したファイルと docutils のソースについてくるファイルでは書き方が少し違う。
自分のファイルをインクルードしたい場合。
$ head /home/hoge/www/pyblosxom/include/icon/icon_mini.inc .. |AKU| image:: http://log-rotation.jp/pyblosxom/images/mini/AKU.png :alt: AKU.png .. |ATARASII| image:: http://log-rotation.jp/pyblosxom/images/mini/ATARASII.png :alt: ATARASII.png .. |AWARE| image:: http://log-rotation.jp/pyblosxom/images/mini/AWARE.png :alt: AWARE.png .. |AYAMARI| image:: http://log-rotation.jp/pyblosxom/images/mini/AYAMARI.png :alt: AYAMARI.png .. |BIKKURI| image:: http://log-rotation.jp/pyblosxom/images/mini/BIKKURI.png :alt: BIKKURI.png . .こんなファイルを用意しておき、reStructuredText ファイルでインクルードして使う。
.. include:: /home/hoge/www/pyblosxom/include/icon/icon_mini.inc |AKU| |ATARASII| |AWARE| |AYAMARI| |BIKKURI|こういう風に表示される。
Docutils についてくるファイルをインクルードする場合。
$ head local/lib/python/docutils/parsers/rst/include/isobox.txt .. This data file has been placed in the public domain. .. Derived from the Unicode character mappings available from <http://www.w3.org/2003/entities/xml/>. Processed by unicode2rstsubs.py, part of Docutils: <http://docutils.sourceforge.net>. .. |boxDL| unicode:: U+02557 .. BOX DRAWINGS DOUBLE DOWN AND LEFT .. |boxDl| unicode:: U+02556 .. BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE .. |boxdL| unicode:: U+02555 .. BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE .. |boxdl| unicode:: U+02510 .. BOX DRAWINGS LIGHT DOWN AND LEFT . . .. include:: <isobox.txt> |boxDL| |boxDl| |boxdL| |boxdl|. Processed by unicode2rstsubs.py, part of Docutils: . —>こういう風に表示される。
╗ ╖ ╕ ┐
インクルードディレクトリは知ってるんだな。





