高橋マインドポイント(2)
ちょっと改良。
- 文字を中央に配置
- 一番長い行が横に収まるように調整
MsoAnchorCenter = 2 MsoAnchorMiddle = 3 class PowerPoint < Excel_Wrapper def takahashi_mind(pre, text) @width ||= pre.pageSetup.slideWidth @height ||= pre.pageSetup.slideHeight s = pre.slides.add( 'Index' => pre.slides.count + 1, 'Layout' => PowerPoint::PpLayoutBlank) tb = s.shapes.addTextBox( MsoTextOrientationHorizontal, 0, 0, @width, @height) tf = tb.textFrame tf.horizontalAnchor = MsoAnchorCenter tf.verticalAnchor = MsoAnchorMiddle tr = tf.textRange tr.text = text.tr("\n", "\r") tr.font.size = fit_font_size(@width, @height, text) tr.paragraphFormat.alignment = PowerPoint::PpAlignCenter sr = s.shapes.range(1) sr.distribute(MsoDistributeVertically, true) end def fit_font_size(width, height, text) (width * 1.8 / (text.map { |s| s.size } << 1).max).to_i end end