/*
	Antenna House PDF Tool API V8.0
	C++ Interface sample program

	概要：下線付き文字列・取り消し線付き文字列・太字、斜体の文字列・枠で囲った文字列（背景色あり）

	Copyright 2025- Antenna House, Inc.
*/

#include < PdfTk.h >

using namespace std;
using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc != 2)
	{
		printf("usage: DrawTextBox_2.exe out-pdf-file \n");
		return 1;
	}

	try {
		PtlParamOutput output(argv[1]);
		PtlPDFDocument doc;

		PtlOption option;
		option.setUnit(PtlOption::UNIT_MM);

		float fontSize = 24.0f;
		PtlParamString fontname = "メイリオ";

		PtlParamFont fontNormal(fontname, fontSize, false, false, true);
		PtlParamFont fontBoldItalic(fontname, fontSize, true, true, true);
		PtlPages& pages = doc.getPages();
		PtlPage newpage;// 新しいページ
		PtlRect rectA4(0.0f, 0.0f, 297.0f, 210.0f);	// A4横用紙

		newpage.setViewBox(rectA4);
		pages.append(newpage, PtlPages::INSERT_OPTION::OPTION_NONE);

		PtlSize pageSize = newpage.getSize();
		PtlContent& content = newpage.getContent();

		PtlRect rect1 = PtlRect(10, 10, pageSize.getWidth() - 20, pageSize.getHeight() - 60);
		PtlTextBox& textBox = content.drawTextBox(rect1, PtlContent::ALIGN::ALIGN_TOP_LEFT, pageSize.getWidth() - 30, pageSize.getHeight() - 70);
		PtlParamWriteStringTextBox paramWriteString = PtlParamWriteStringTextBox();
		PtlParamWriteStringTextBox paramWriteStringBoldItalic = PtlParamWriteStringTextBox();

		paramWriteString.setFont(fontNormal);

		paramWriteString.setUnderline(true);
		const char* text1 = ("下線はPtlParamWriteStringTextBoxで指定して書くことができます。");
		textBox.writeStringNL(text1, paramWriteString);
		paramWriteString.setUnderline(false);

		textBox.writeNL();

		paramWriteString.setStrikeOut(true);
		const char* text2 = ("取り消し線はPtlParamWriteStringTextBoxで指定して書くことができます。");
		textBox.writeStringNL(text2, paramWriteString);
		paramWriteString.setStrikeOut(false);

		textBox.writeNL();

		paramWriteStringBoldItalic.setFont(fontBoldItalic);
		const char* text3 = ("太字、斜体のフォントスタイルはPtlParamFontで設定します。");
		textBox.writeStringNL(text3, paramWriteStringBoldItalic);
		textBox.terminate();

		PtlColorDeviceRGB colorBack = PtlColorDeviceRGB(1.0f, 0.8f, 0.8f);
		PtlColorDeviceRGB colorRed = PtlColorDeviceRGB(1.0f, 0.0f, 0.0f);
		PtlRect rect2 = PtlRect(130, 10, pageSize.getWidth() - 10, pageSize.getHeight() - 150);
		PtlTextBox& textBox2 = content.drawTextBox(rect2, PtlContent::ALIGN::ALIGN_TOP_LEFT, pageSize.getWidth() - 140, pageSize.getHeight() - 160);

		textBox2.setBackColor(colorBack);    // 背景色を設定
		textBox2.setOutlineColor(colorRed);  // テキストボックスの縁取り色を設定
		textBox2.setOpacity(0.6f);           // 不透明度を設定
		textBox2.fitToBBox(false);           // TextBoxのサイズをテキストに合わせるかどうか(true:合わせる)

		paramWriteString.setFont(fontNormal);

		const char* text4 = ("枠で囲った文字列（背景色あり）は PtlTextBox に色を指定して書くことができます。");
		textBox2.writeStringNL(text4, paramWriteString);

		textBox2.terminate();

		doc.save(output);

		printf("-- 完了 --\n");

	} catch (PtlException e) {
		fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());

	} catch (...) {
		printf("Exception\n");
	}
}