Curl® 言語は印刷用APIを提供し、それを実装することによってユーザーがプリンタの選択や、印刷設定が行えるアプレットを作成できます。またユーザーの介入なしで特定のプリンタに調整されたセッティングでの印刷機能をもったアプリケーションを作成できます。
print-graphic プロシージャは、Curl のアプリケーションから印刷するための、強力で柔軟性のあるツールです。グラフィック コンテンツを選択されたプリンタと用紙に対してフォーマットし、ページネーション、余白、およびページの印字禁止領域を処理します。
次の例では、テキスト抜粋部分を印刷することにより、
print-graphic の既定の動作を説明します。既定では、日付とページ番号がページの下部に印刷されることに注意してください。引数
print-date? と
print-page-numbers? がこの動作を制御します。ページの左上(北西・north west)の角にテキストを追加する
nw-title と、ページの右上(北東・north east)の角にテキストを追加する
ne-title を使用して、ページの上部にタイトルを追加することができます。ヘッダーおよびフッターのテキストを追加するこれらの引数は、それぞれが対応する引数を持ち、フォントサイズを制御します。
print-graphic プロシージャはプリンタ ダイアログを開き、これによりユーザーはプリンタを選択することができます。引数
show-printer-dialog? はこの動作を制御します。
例:
print-graphic の既定動作 |
|
{CommandButton
label="Print",
{on Action do
let pf =
{print-graphic
{evaluate
{url "../../default/support/text-content.scurl"}
}
}
}
}
| |
次の例では、ビューに表示されたテキストを印刷するメニュー アイテムを指定します。これはビューのタイトルを使用して印刷されたページに nw-title を設定します。
例:
ビュー内におけるテキスト印刷 |
|
{import * from CURL.GRAPHICS.PRINTER}
{value
let text-space:Frame =
{Frame
{evaluate
{url "../../default/support/text-content.scurl"}
}
}
let display-box:VBox = {VBox}
let title:String = "The Gettysburg Address"
let menu-bar:MenuBar =
{MenuBar
{SubMenu
label = {text File},
{MenuAction
label = {text Print},
{on Action do
let pf =
{print-graphic
text-space,
nw-title = title
}
}
}
}
}
{display-box.add menu-bar}
{display-box.add text-space}
{CommandButton
label = "Show View",
{on Action do
let text-view:View = {View}
set text-view.title = title
{text-view.add display-box}
{text-view.show}
}
}
}
| |
例:
page-setup-dialog の使用 |
|
{import * from CURL.GRAPHICS.PRINTER}
{CommandButton label="Print",
{on Action do
{page-setup-dialog
print-margin =
{PrintMargin
2cm,
1cm,
2cm,
1cm
}
}
let pf =
{print-graphic
{evaluate
{url "../../default/support/text-content.scurl"}
}
}
}
}
| |
print-graphic を使用して、エンドユーザーの操作を必要とせずに指定されたプリンタと用紙に印刷する Curl のアプレットを作成することができます。次の例では、既定のプリンタを使用して DL 封筒のサイズに住所を印刷します。名前と住所の情報はサポート ファイル内のデータから作成された
RecordSet からのものです。
この例は、例を実行するコンピューターにインストールされた DL 封筒をサポートする既定のプリンタに依存するので、ここではソース コードとして示されています。コードをアプレットにコピーして貼り付け、適切に設定されたマシン上で実行してください。場合によっては、設定を反映するために、プリンタと用紙の設定変更が必要となります。
この例では、ページ余白を設定し、日付とページ番号を削除します。
multi-part と
printing-frame を使用して単一の、複数ページの印刷ジョブとして生成されたページを印刷します。
printing-frame を
print-graphic によって返された
PrintRootFrame に設定しない場合、各ページは別々のドキュメントとしてプリンタに送られます。これは、別々の
Printer オブジェクトが各ページに作成されたことを意味します。追加の
Printer オブジェクトの作成は、追加のリソースを消費します。そのため、可能な限り
PrintRootFrame を再利用するとよいでしょう。定型化した手紙を印刷していて、それぞれの手紙に 1 から始まるページ番号を表示する必要がある場合は、それぞれの手紙に新しい
PrintRootFrame を作成する必要があります。
{import * from CURL.GRAPHICS.PRINTER}
{import * from CURL.DATA-ACCESS.BASE}
{value
let people:RecordSet =
{evaluate
{url "../../default/support/data-addresses.scurl"}
}
let my-printer:String = {Printer.get-default-printer}
let printer-pages:#{Array-of PrintPageDescription} =
{Printer.get-page-description my-printer}
let my-page-description:any
let margin-width:Distance = 1cm
{if-non-null printer-pages then
{for p:PrintPageDescription in printer-pages do
{if {p.description.find-string "Envelope DL"} == 0 then
set my-page-description = p
}
}
else
{popup-message "No such paper"}
}
let content:Grid =
{Grid
height = my-page-description.width - 2 * margin-width
}
{content.add
top = {content.top},
left = {content.left},
{VBox
{image source = {url "../../default/images/curllogo.gif"}},
{text 201 Broadway, Second Floor},
{text Cambridge MA, 02139}
}
}
let address-box:VBox = {VBox}
{content.add
top = {content.top},
left = {content.left},
address-box
}
let envelope-frame:#PrintRootFrame
{CommandButton label="Print Envelopes",
{on Action do
let count:int = 0
let mp:bool = true
{for person:Record in people do
{if envelope-frame == null then || it was canceled
break
}
{if count == people.size - 1 then
set mp = false
}
{address-box.clear}
{address-box.add
{format "%s %s", person["First"], person["Last"]}}
{address-box.add person["Street"]}
{address-box.add
{format "%s %s", person["City"], person["State"]}}
set envelope-frame =
{print-graphic
content,
left-margin = 1cm,
right-margin = 1cm,
top-margin = 1cm,
bottom-margin = 1cm,
print-page-numbers?=false,
print-date? = false,
multi-part?=mp,
show-printer-dialog? = false,
printer-name = my-printer,
orientation = "landscape",
page-description = my-page-description,
printing-frame = envelope-frame
}
set count = count + 1
}
}
}
}
Copyright © 1998-2019 SCSK Corporation.
All rights reserved.
Curl, the Curl logo, Surge, and the Surge logo are trademarks of SCSK Corporation.
that are registered in the United States. Surge
Lab, the Surge Lab logo, and the Surge Lab Visual Layout Editor (VLE)
logo are trademarks of SCSK Corporation.