diff --git a/.gitignore b/.gitignore index e58a4ce..10233ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store vendor/ +output* diff --git a/award.php b/award.php index daeaca4..fd61675 100644 --- a/award.php +++ b/award.php @@ -12,100 +12,11 @@ use PhpOffice\PhpPresentation\Slide; use PhpOffice\PhpPresentation\Slide\Background\Image; use PhpOffice\PhpPresentation\Style\Fill; - -/** - * add Rich Text Shape テキストボックスの追加 - * A4 Paper size by UNIT_PIXEL = 794 x 1123 - */ -function addRTShape( - PhpPresentation $pres, - Slide $slide, - int $intw, // 幅のピクセル数 - float $ypercent, // ボックスのY座標を、パーセントで。(50だとちょうど半分、中央の高さ) - string $mes, - int $size, - string $h_alignment = Alignment::HORIZONTAL_CENTER, - string $v_alignment = Alignment::VERTICAL_AUTO -) { - $oLayout = $pres->getLayout(); - // $intw = 600;//(int)( ($oLayout->getCX($oLayout::UNIT_PIXEL) * 0.8)); - $inth = 300; // 固定値 (int)($oLayout->getCY($oLayout::UNIT_PIXEL)); - $intoffx = (int)(($oLayout->getCX($oLayout::UNIT_PIXEL) - $intw) / 2); - $intoffy = (int)(($oLayout->getCY($oLayout::UNIT_PIXEL) * $ypercent / 100)); - // echo $oLayout->getCX($oLayout::UNIT_PIXEL) . " " . $intw . " " . $inth . " " . $intoffx . " " . $intoffy . "\n"; - - $shape2 = $slide->createRichTextShape() - ->setWidth($intw) // 794px - ->setHeight($inth) // 1123px - ->setOffsetX($intoffx) - ->setOffsetY($intoffy); - $shape2->getActiveParagraph() - ->getAlignment() - ->setHorizontal($h_alignment) - ->setVertical($v_alignment); - - $textRun2 = $shape2->createTextRun($mes); - - $textRun2->getFont() - ->setName('ヒラギノ明朝 Pro W3') // TODO: Windowsの場合は変更が必要かも - ->setBold(false) - ->setSize($size) - ->setColor(new Color('FF000000')); // 最初のFFは不透明度。そのあとRRGGBB - $shape2->getActiveParagraph()->setLineSpacing(120); // 行間(Line Spacing)。100だとぴったり。150だと1.5倍 - -} - -/** - * $ary['title'] - * $ary['authors] = [ "著者1" , "著者2", ...] - */ -function addHSJ(PhpPresentation $pres, $ary) -{ - $pres->createSlide(); - $pres->setActiveSlideIndex($pres->getSlideCount() - 1); - $slide = $pres->getActiveSlide(); - - addRTShape($pres, $slide, 600, 15, "インタラクション2023", 23); - addRTShape($pres, $slide, 600, 20, "インタラクティブ発表賞(PC推薦)", 26); - - $authors = ""; //著者名 - $aindex = 0; - if (count($ary['authors']) % 2 == 1) { //著者人数が奇数 - $authors .= $ary['authors'][0] . "殿\r\n"; //まず、筆頭著者を書く - $aindex = 1; - } - for ($i = $aindex; $i < count($ary['authors']); $i += 2) { - $authors .= $ary['authors'][$i] . "殿  "; // 残りを2人ずつ書く - $authors .= $ary['authors'][$i + 1] . "殿"; - $authors .= "\r\n"; - } - $additionalline = 0; - if (count($ary["authors"]) > 2) { //著者の行が増えたことを考慮し、本文をすこし下げる - $additionalline = floor((count($ary["authors"]) - 1) / 2); - // echo "additional " . $additionalline . "\n"; - } - addRTShape($pres, $slide, 600, 18.5 + $additionalline * 1.2, $authors, 24, Alignment::HORIZONTAL_CENTER, Alignment::VERTICAL_CENTER); - addRTShape($pres, $slide, 576, 36.5 + $additionalline * 2, "貴殿が本学会シンポジウム インタラクション2023において発表された" . - "「{$ary['title']}」" . - "は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" . - "今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします", 18, Alignment::HORIZONTAL_GENERAL); - - addRTShape($pres, $slide, 520, 67 + $additionalline , "令和5年3月10日\r\n" . - "一般社団法人 情報処理学会\r\n" . - "インタラクション2023\r\n" . - "大会委員長 寺田 努 \r\n" . - "プログラム委員長 竹川 佳成\r\n" . - "インタラクティブ発表委員長 生田 泰章\r\n", 18, Alignment::HORIZONTAL_RIGHT); - - return $slide; //あとで使うことがなければ、必要ない -} +use PhpOffice\PhpPresentation\Shape\Drawing; +use PhpOffice\PhpPresentation\Style\Border; //新規プレゼンテーション作成 $phpPres = new PhpPresentation(); -// $phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_SCREEN_16X9); -$phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_A4, false); //false=portrait -//A4のサイズはEMUで、self::LAYOUT_A4 => ['cx' => 10692000, 'cy' => 7560000], -// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']); //ドキュメントのプロパティ設定 $phpPres->getDocumentProperties() ->setCreator('@IPSJ') @@ -113,7 +24,85 @@ ->setTitle('インタラクション2023表彰状') ->setDescription('インタラクション2023表彰状'); - /////////////////////////////////////////////////////////// +// 印刷用(A4)なら1、16x9なら2を選択 +echo "印刷用(A4)なら 1 、クロージング用(16x9)なら 2 を入力してください。\n"; +$type = trim(fgets(STDIN)); +$outfile = "output表彰状{$type}.pptx"; +echo "「{$type}」が入力されました。「{$outfile}」に出力します。\n"; +sleep(1); + +//A4のサイズはEMUで、self::LAYOUT_A4 => ['cx' => 10692000, 'cy' => 7560000], +// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']); +if ($type == "1") { + $phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_A4, false); //false=portrait + require_once 'lib_a4.php'; + + //マスタースライドに画像を設定 + // $oMasterSlide = $phpPres->getAllMasterSlides()[0]; + // $oBkgImage = new Image(); + // $oBkgImage->setPath('template1.jpg'); //PDFでもよいが、開く時に、修復が必要になる + // $oMasterSlide->setBackground($oBkgImage); + + $oLayout = $phpPres->getLayout(); + $width = $oLayout->getCX($oLayout::UNIT_PIXEL); + $height = $oLayout->getCY($oLayout::UNIT_PIXEL); + // 印刷するときはスライドマスターと、コンテンツのあいだに、白い矩形をはさんでおくとよいかもしれない + // $cover = $oMasterSlide->createRichTextShape()->setHeight(1123)->setWidth(794) + // ->setOffsetX(0)->setOffsetY(0); + // $cover->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(45)->setStartColor(new Color('FFffffff'))->setEndColor(new Color('FFffffff')); + +} else if ($type == "2") { + $phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_SCREEN_16X9, true); + require_once 'lib_16x9.php'; + + //マスタースライドに画像を設定 + $oMasterSlide = $phpPres->getAllMasterSlides()[0]; + // $oBkgImage = new Image(); + // $oBkgImage->setPath('template1.jpg'); //PDFでもよいが、開く時に、修復が必要になる + + $oLayout = $phpPres->getLayout(); + $width = $oLayout->getCX($oLayout::UNIT_PIXEL); + $height = $oLayout->getCY($oLayout::UNIT_PIXEL); + + $a4width = floor($height / 1.41); + echo "a4width = {$a4width}\n"; + $img = new Drawing\File(); + $hamidasi = 16; // X方向の画像はみだし量(pixel) Y方向のはみだし量は、これの1.4倍になる + $img->setName('Image File') + ->setDescription('Image File') + ->setPath('template1.jpg') + ->setHeight($height + round($hamidasi*2*1.4)) + ->setOffsetX(($width - $a4width) / 2 - $hamidasi) + ->setOffsetY(round(-$hamidasi*1.4)); + $img->getBorder()->setColor(new Color('FFffffff'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE); + $oMasterSlide->addShape($img); + // 紙のまわりの枠線(画像の縁よりも、すこし内側に表示する) + $border = $oMasterSlide->createRichTextShape() + ->setHeight($height) + ->setWidth($a4width) + ->setOffsetX(($width - $a4width) / 2) + ->setOffsetY(0); + $border->getFill()->setFillType(Fill::FILL_NONE); + $border->getBorder()->setColor(new Color('FF333333'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE); + + // $img の左ボーダーが消えないので、白い矩形を置く + $kesi = $oMasterSlide->createRichTextShape() + ->setHeight($height + $hamidasi*2) + ->setWidth(20) + ->setOffsetX(($width - $a4width) / 2 - $hamidasi -10) + ->setOffsetY(-$hamidasi); + $kesi->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FFffffff'))->setEndColor(new Color('FFffffff')); + // $kesi->getBorder()->setColor(new Color('FFffffff'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE); + + // $oMasterSlide->setBackground($oBkgImage); +} + + +// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']); +// $height = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cy']); +echo "width {$width} pixels x height {$height} pixels \n"; + +/////////////////////////////////////////////////////////// $ary = [ "title" => "PHPPresentationを利用した表彰状の作成", @@ -138,18 +127,8 @@ $phpPres->removeSlideByIndex(0); // 最初のスライドを削除する -//マスタースライドに画像を設定 -$oMasterSlide = $phpPres->getAllMasterSlides()[0]; -$oBkgImage = new Image(); -$oBkgImage->setPath('template3.png'); //PDFでもよいが、開く時に、修復が必要になる -$oMasterSlide->setBackground($oBkgImage); - -// 印刷するときはスライドマスターと、コンテンツのあいだに、白い矩形をはさんでおくとよいかもしれない -// $cover = $oMasterSlide->createRichTextShape()->setHeight(1123)->setWidth(794) -// ->setOffsetX(0)->setOffsetY(0); -// $cover->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(45)->setStartColor(new Color('FFffffff'))->setEndColor(new Color('FFffffff')); $oWriterPPTX = IOFactory::createWriter($phpPres, 'PowerPoint2007'); -$oWriterPPTX->save(__DIR__ . "/output表彰状.pptx"); +$oWriterPPTX->save(__DIR__ . "/{$outfile}"); // $oWriterODP = IOFactory::createWriter($phpPres, 'ODPresentation'); // $oWriterODP->save(__DIR__ . "/sample.odp"); diff --git a/lib_16x9.php b/lib_16x9.php new file mode 100644 index 0000000..f585e48 --- /dev/null +++ b/lib_16x9.php @@ -0,0 +1,102 @@ +getLayout(); + // $intw = 600;//(int)( ($oLayout->getCX($oLayout::UNIT_PIXEL) * 0.8)); + $inth = 300; // 固定値 (int)($oLayout->getCY($oLayout::UNIT_PIXEL)); + $intoffx = (int)(($oLayout->getCX($oLayout::UNIT_PIXEL) - $intw) / 2); + $intoffy = (int)(($oLayout->getCY($oLayout::UNIT_PIXEL) * $ypercent / 100)); + // echo $oLayout->getCX($oLayout::UNIT_PIXEL) . " " . $intw . " " . $inth . " " . $intoffx . " " . $intoffy . "\n"; + + $shape2 = $slide->createRichTextShape() + ->setWidth($intw) // 794px + ->setHeight($inth) // 1123px + ->setOffsetX($intoffx) + ->setOffsetY($intoffy); + $shape2->getActiveParagraph() + ->getAlignment() + ->setHorizontal($h_alignment) + ->setVertical($v_alignment); + + $textRun2 = $shape2->createTextRun($mes); + + $textRun2->getFont() + ->setName('ヒラギノ明朝 Pro W3') // TODO: Windowsの場合は変更が必要かも + ->setBold(false) + ->setSize($size) + ->setColor(new Color('FF000000')); // 最初のFFは不透明度。そのあとRRGGBB + $shape2->getActiveParagraph()->setLineSpacing(120); // 行間(Line Spacing)。100だとぴったり。150だと1.5倍 + +} + +/** + * $ary['title'] + * $ary['authors] = [ "著者1" , "著者2", ...] + */ +function addHSJ(PhpPresentation $pres, $ary) +{ + $pres->createSlide(); + $pres->setActiveSlideIndex($pres->getSlideCount() - 1); + $slide = $pres->getActiveSlide(); + + $w600 = (int)(382*600/794); + $w576 = (int)(382*576/794); + $w520 = (int)(382*520/794); + + addRTShape($pres, $slide, $w600, 15, "インタラクション2023", 11); + addRTShape($pres, $slide, $w600, 20, "インタラクティブ発表賞(PC推薦)", 12); + + $authors = ""; //著者名 + $aindex = 0; + if (count($ary['authors']) % 2 == 1) { //著者人数が奇数 + $authors .= $ary['authors'][0] . "殿\r\n"; //まず、筆頭著者を書く + $aindex = 1; + } + for ($i = $aindex; $i < count($ary['authors']); $i += 2) { + $authors .= $ary['authors'][$i] . "殿  "; // 残りを2人ずつ書く + $authors .= $ary['authors'][$i + 1] . "殿"; + $authors .= "\r\n"; + } + $additionalline = 0; + if (count($ary["authors"]) > 2) { //著者の行が増えたことを考慮し、本文をすこし下げる + $additionalline = floor((count($ary["authors"]) - 1) / 2); + // echo "additional " . $additionalline . "\n"; + } + addRTShape($pres, $slide, $w600, 6.2 + $additionalline * 0.6, $authors, 11, Alignment::HORIZONTAL_CENTER, Alignment::VERTICAL_CENTER); + addRTShape($pres, $slide, $w576, 36.5 + $additionalline * 2, "貴殿が本学会シンポジウム インタラクション2023において発表された" . + "「{$ary['title']}」" . + "は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" . + "今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします", 9, Alignment::HORIZONTAL_GENERAL); + + addRTShape($pres, $slide, $w520, 66 + $additionalline, "令和5年3月10日\r\n" . + "一般社団法人 情報処理学会\r\n" . + "インタラクション2023\r\n" . + "大会委員長 寺田 努 \r\n" . + "プログラム委員長 竹川 佳成\r\n" . + "インタラクティブ発表委員長 生田 泰章\r\n", 9, Alignment::HORIZONTAL_RIGHT); + + return $slide; //あとで使うことがなければ、必要ない +} diff --git a/lib_a4.php b/lib_a4.php new file mode 100644 index 0000000..35f8a0c --- /dev/null +++ b/lib_a4.php @@ -0,0 +1,98 @@ +getLayout(); + // $intw = 600;//(int)( ($oLayout->getCX($oLayout::UNIT_PIXEL) * 0.8)); + $inth = 300; // 固定値 (int)($oLayout->getCY($oLayout::UNIT_PIXEL)); + $intoffx = (int)(($oLayout->getCX($oLayout::UNIT_PIXEL) - $intw) / 2); + $intoffy = (int)(($oLayout->getCY($oLayout::UNIT_PIXEL) * $ypercent / 100)); + // echo $oLayout->getCX($oLayout::UNIT_PIXEL) . " " . $intw . " " . $inth . " " . $intoffx . " " . $intoffy . "\n"; + + $shape2 = $slide->createRichTextShape() + ->setWidth($intw) // 794px + ->setHeight($inth) // 1123px + ->setOffsetX($intoffx) + ->setOffsetY($intoffy); + $shape2->getActiveParagraph() + ->getAlignment() + ->setHorizontal($h_alignment) + ->setVertical($v_alignment); + + $textRun2 = $shape2->createTextRun($mes); + + $textRun2->getFont() + ->setName('ヒラギノ明朝 Pro W3') // TODO: Windowsの場合は変更が必要かも + ->setBold(false) + ->setSize($size) + ->setColor(new Color('FF000000')); // 最初のFFは不透明度。そのあとRRGGBB + $shape2->getActiveParagraph()->setLineSpacing(120); // 行間(Line Spacing)。100だとぴったり。150だと1.5倍 + +} + +/** + * $ary['title'] + * $ary['authors] = [ "著者1" , "著者2", ...] + */ +function addHSJ(PhpPresentation $pres, $ary) +{ + $pres->createSlide(); + $pres->setActiveSlideIndex($pres->getSlideCount() - 1); + $slide = $pres->getActiveSlide(); + + addRTShape($pres, $slide, 600, 15, "インタラクション2023", 23); + addRTShape($pres, $slide, 600, 20, "インタラクティブ発表賞(PC推薦)", 26); + + $authors = ""; //著者名 + $aindex = 0; + if (count($ary['authors']) % 2 == 1) { //著者人数が奇数 + $authors .= $ary['authors'][0] . "殿\r\n"; //まず、筆頭著者を書く + $aindex = 1; + } + for ($i = $aindex; $i < count($ary['authors']); $i += 2) { + $authors .= $ary['authors'][$i] . "殿  "; // 残りを2人ずつ書く + $authors .= $ary['authors'][$i + 1] . "殿"; + $authors .= "\r\n"; + } + $additionalline = 0; + if (count($ary["authors"]) > 2) { //著者の行が増えたことを考慮し、本文をすこし下げる + $additionalline = floor((count($ary["authors"]) - 1) / 2); + // echo "additional " . $additionalline . "\n"; + } + addRTShape($pres, $slide, 600, 18.5 + $additionalline * 1.2, $authors, 24, Alignment::HORIZONTAL_CENTER, Alignment::VERTICAL_CENTER); + addRTShape($pres, $slide, 576, 36.5 + $additionalline * 2, "貴殿が本学会シンポジウム インタラクション2023において発表された" . + "「{$ary['title']}」" . + "は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" . + "今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします", 18, Alignment::HORIZONTAL_GENERAL); + + addRTShape($pres, $slide, 520, 67 + $additionalline, "令和5年3月10日\r\n" . + "一般社団法人 情報処理学会\r\n" . + "インタラクション2023\r\n" . + "大会委員長 寺田 努 \r\n" . + "プログラム委員長 竹川 佳成\r\n" . + "インタラクティブ発表委員長 生田 泰章\r\n", 18, Alignment::HORIZONTAL_RIGHT); + + return $slide; //あとで使うことがなければ、必要ない +} diff --git a/template1.jpg b/template1.jpg new file mode 100644 index 0000000..8b78270 --- /dev/null +++ b/template1.jpg Binary files differ diff --git a/template1.pdf b/template1.pdf new file mode 100644 index 0000000..c2e4234 --- /dev/null +++ b/template1.pdf Binary files differ