/** * @fileoverview 指定領域の背景に画像を入れる * @author Kenshi Muto <kmuto@debian.org> * @requires libCommon.jsx * @requires libGetBoundsOfPage.jsx * @version 2,3 */ /* Copyright: 2008 Kenshi Muto ---------------------------------------------------------------------- ソフトウェア使用許諾同意書 本ソフトウェアの利用・変更・再配布にあたっては、下記の使用許諾同意書に 同意する必要があります。 1. 本使用許諾同意書における「ソフトウェア」とは、機械可読の資料 (ライブ ラリ、スクリプト、ソースファイル、データファイル)、実行形式、および 文書を意味します。 2. 本ソフトウェアの使用許諾同意書に同意する限りにおいて、使用者は 本ソフトウェアを自由に利用、変更することができます。 3. 本ソフトウェアに変更を加えない限りにおいて、使用者は本ソフトウェアを 自由にコピー、再配布することができます。 4. 本ソフトウェアは無保証です。作者およびそれに関連する組織、配布者は、 本ソフトウェアの使用に起因する一切の直接損害、間接損害、偶発的損害、 特別損害、懲戒的損害、派生的損害について何らの責任・保証も負いません。 5. 本ソフトウェアを変更した上で再配布するときには、下記の事項すべてに 従わなければなりません。 - 使用許諾同意書の内容に変更を加えてはなりません。技術上の理由で 文字エンコーディングの変換を行うことは許可しますが、その使用者が 特殊な技術的措置なしに可読な形でなければなりません。 - 技術上の理由でバイナリ化・難読化を行う場合も、変更箇所を含めた ソフトウェアを、その使用者が可読可能な形式の形で同一のメディアで 提供しなければなりません。本使用許諾同意書の2条および3条により、 使用者が可読形式の該当ソフトウェアを変更、コピー、再配布することを 妨げてはなりません。 - ソフトウェア構成物の所定の作者名の欄に、変更者のクレジット (個人名、企業名、所属、連絡先など)を「追加」しなければなりません。 6. 本ソフトウェアを変更した上で再配布するときには、変更理由および その内容を明記することが推奨されます。 7. 使用者がソフトウェアに適用可能な特許に対して特許侵害にかかわる何らか の行動を開始した時点で、この使用許諾同意書は自動的に終了し、以降 使用者はこの使用許諾書によって与えられた一切の権利を放棄するものと します。 著作権所有者 Copyright (C) 2008 Kenshi Muto. All rights reserved. 使用許諾同意書バージョン1.0 著作権所有者による書面での事前の許可がない限り、この使用許諾同意書 に変更を加えてはなりません。 ---------------------------------------------------------------------- */ #include "../libs/libCommon.jsx" #include "../libs/libGetBoundsOfPage.jsx" /** * 指定の画像をストーリーの開始オフセットから終了オフセットのボックス範囲の背景に配置する。オブジェクトオフセットおよび画像ファイルオブジェクトはページごとに指定できる。配列がページ数に満たなかった場合、その最後のオブジェクトが使われる。オフセットとファイルは別個に指定できる * @param {String} layername 配置レイヤー。nullのときには現在のレイヤーを使う * @param {Story} story ストーリーオブジェクト * @param {Long} startpoint 開始オフセット * @param {Long} endpoint 終了オフセット * @param {Long[][4]} offsetunits 各ページごとのオフセット値 * @param {File[]} files 各ページごとの画像ファイルオブジェクト * @param {ObjectStyle} ostyle オブジェクトスタイルオブジェクト * @param {boolean} lfit 左端を版面に合わせるか(true=合わせる、false=合わせずに先頭文字から判定) * @param {Float} width ボックスの幅。nullの場合には文字位置から算出 * @param {boolean} fit ページをまたぐときにオフセット前の下の位置を版面に合わせる(true=合わせる、false=合わせない) * @type Nothing */ function backGroundImage(layername, story, startpoint, endpoint, offsetunits, files, ostyle, lfit, width, fit) { var startpage, endpage; if (getCSVersion() == 2) { startpage = story.characters[startpoint].insertionPoints[0].parentTextFrames[0].parent; endpage = story.characters[endpoint].insertionPoints[0].parentTextFrames[0].parent; } else { // XXX: CS3 startpage = startpoint.parentTextFrames[0].parent; endpage = endpoint.parentTextFrames[0].parent; } var blocks = new Array(); var unit = new Array(4); var backunit = toMmMode(story.parent); var backruler = story.parent.viewPreferences.rulerOrigin; story.parent.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin; var backunit2 = story.parent.viewPreferences.horizontalMeasurementUnits; story.parent.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters; if (getCSVersion() == 2) { unit[1] = story.characters[startpoint].insertionPoints[0].horizontalOffset; // X1 unit[0] = story.characters[startpoint].insertionPoints[0].baseline - pttomm(story.characters[startpoint].insertionPoints[0].pointSize * 0.8); // Y1 unit[3] = story.characters[endpoint].insertionPoints[0].horizontalOffset; // X2 unit[2] = story.characters[endpoint].insertionPoints[0].baseline + pttomm(story.characters[endpoint].insertionPoints[0].pointSize * 0.2); // Y2 } else { // XXX: CS3 unit[1] = startpoint.horizontalOffset; // X1 unit[0] = startpoint.baseline - pttomm(startpoint.pointSize * 0.8); // Y1 unit[3] = endpoint.horizontalOffset; // X2 unit[2] = endpoint.baseline + pttomm(endpoint.pointSize * 0.2); // Y2 } var point; var page = startpage; var sp, ep; if (getCSVersion() == 2) { sp = startpoint; ep = endpoint; } else { // XXX: CS3 sp = startpoint.index; ep = endpoint.index; } for (var i = sp; i <= ep; i++) { point = story.characters[i].insertionPoints[0]; if (point.baseline < unit[0]) { // 上に移動、ページが変わる blocks.push([page, unit[0], unit[2], unit[1]]); unit[0] = point.baseline - pttomm(point.pointSize * 0.8); unit[1] = point.horizontalOffset; } if (point.horizontalOffset < unit[1]) unit[1] = point.horizontalOffset; // 左にもっと移動 if (point.horizontalOffset > unit[3]) unit[3] = point.horizontalOffset; // 右に移動 if (point.baseline + pttomm(point.pointSize * 0.2) > unit[2]) unit[2] = point.baseline + pttomm(point.pointSize * 0.2); // 下に移動 くるはずはないが… page = point.parentTextFrames[0].parent; } unit[2] = story.characters[ep].insertionPoints[0].baseline + pttomm(story.characters[ep].insertionPoints[0].pointSize * 0.2); // Y2 blocks.push([point.parentTextFrames[0].parent, unit[0], unit[2], unit[1]]); var offsetunit; var hasfile = null; for (var i = 0; i < blocks.length; i++) { unit[0] = blocks[i][1]; unit[2] = blocks[i][2]; unit[1] = blocks[i][3]; if (getCSVersion() == 2) { page = story.parent.pages[startpage.documentOffset + i - 1]; } else { // XXX: CS3 page = story.parent.pages[startpage.documentOffset + i]; } if (i < offsetunits.length - 1) { offsetunit = offsetunits[i]; } else { offsetunit = offsetunits[offsetunits.length - 1]; } if (fit == true && i < blocks.length - 1) { // fitオプションがtrueでページ途中であれば下を合わせる unit[2] = getBoundsOfPage(story.parent, page)[2]; } if (lfit == true) { // fitオプションがtrueであれば左を合わせる unit[1] = getBoundsOfPage(story.parent, page)[1]; } if (width != null) { unit[3] = unit[1] + width; } var rect; if (layername != null) { var layer = story.parent.layers.item(layername); if (layer == null) { layer = story.parent.layers.add(); layer.label = layername; layer.name = layername; layer.move(LocationOptions.atEnd); } rect = blocks[i][0].rectangles.add({itemLayer: layer}); } else { rect = blocks[i][0].rectangles.add(); } rect.contentType = ContentType.graphicType; rect.appliedObjectStyle = ostyle; rect.geometricBounds = [unit[0] + offsetunit[0], unit[1] + offsetunit[1], unit[2] + offsetunit[2], unit[3] + offsetunit[3]]; var file = null; if (files.length - 1 > i) { file = files[i]; } else { file = files[files.length - 1]; } if (file != null) { hasfile = file; rect.place(file); var rectheight = rect.geometricBounds[2] - rect.geometricBounds[0]; var gheight = rect.graphics[0].geometricBounds[2] - rect.graphics[0].geometricBounds[0]; if (rectheight > gheight) { rect.fit(FitOptions.frameToContent); } } else if (file == null && hasfile != null) { rect.remove(); continue; } rect.sendToBack(); if (getCSVersion() == 2) { try { with(rect) { // 上書きされたオブジェクトスタイルを戻す。FIXME:もっと一発で直せないのか? appliedParagraphStyle = ostyle.appliedParagraphStyle; applyNextParagraphStyle = ostyle.applyNextParagraphStyle; basedOn = ostyle.basedOn; blendMode = ostyle.blendMode; cornerEffect = ostyle.cornerEffect; cornerRadius = ostyle.cornerRadius; endcap = ostyle.endCap; endJoin = ostyle.endJoin; featherCornerType = ostyle.featherCornerType; featherMode = ostyle.featherMode; featherNoise = ostyle.featherNoise; featherWidth = ostyle.featherWidth; defaultFrameGridObjectStyle = ostyle.defaultFrameGridObjectStyle; defaultObjectStyle = ostyle.defaultObjectStyle; defaultTextObjectStyle = ostyle.defaultTextObjectStyle; enableAnchoredObjectOptions = ostyle.enableAnchoredObjectOptions; // FIXME fillColor = ostyle.fillColor; fillTint = ostyle.fillTint; gapColor = ostyle.gapColor; gapTint = ostyle.gapTint; gradientFillAngle = ostyle.gradientFillAngle; strokeColor = ostyle.strokeColor; strokeTint = ostyle.strokeTint; strokeWeight = ostyle.strokeWeight; strokeType = ostyle.strokeType; // FIXME } } catch (e) { continue; }; } else { // XXX: CS3 rect.clearObjectStyleOverrides(); } } story.parent.viewPreferences.horizontalMeasurementUnits = backunit2; story.parent.viewPreferences.rulerOrigin = backruler; revertMmMode(story.parent, backunit); }