もんたマインドポイント

高橋メソッドからもんたメソッドが派生したように、高橋マインドから高橋マインドポイントを経てもんたマインドポイントが生まれたのは当然の流れと言えよう。

  • もんたメソッドの原稿をFreeMindで書く。
  • キーワードは[]で囲む。本当は背景を黒塗りにしたかったけどやり方がわからなかったのでフォントを背景色にしている。

これを、PowerPointに変換する。

ちなみに上の画像だと一部おかしいところがあるけど2007βのバグらしい。

mmpoint.rb

require 'excel_lib'
require 'freemind'

MsoDistributeVertically = 1
MsoTextOrientationHorizontal = 1
MsoAnchorCenter = 2
MsoAnchorMiddle = 3

class PowerPoint < Excel_Wrapper
  def initialize(visible = true)
    @raw_object = connector('PowerPoint.Application')
    @raw_object.visible = visible
    if block_given?
      yield self
      #quit unless @connected
    end
  end

  def connector(app_name)
    begin
      raw_object = WIN32OLE.connect(app_name)
      @connected = true
    rescue
      raw_object = WIN32OLE.new(app_name)
    end
    WIN32OLE.my_const_load(raw_object, self.class)
    raw_object
  end

  def mask(tr, pos, len)
    tr.characters(pos, len).font.color.schemeColor = PowerPoint::PpBackground
  end

  def monta_mask(tr, masks, shown)
    return if shown == masks
    cur = 0
    1.upto(masks) do |i|
      p1 = tr.find('[', cur).start
      p2 = tr.find(']', p1).start
      mask(tr, p1 + 1, p2 - p1 - 1) if shown < i
      cur = p2
    end
  end

  def monta_method(pre, text)
    masks = text.scan(/\[[^\]]*\]/).size
    0.upto(masks) do |shown|
      sl, tb, tf, tr = takahashi_method(pre, text)
      monta_mask(tr, masks, shown)
    end
  end

  def takahashi_method(pre, text)
    @width ||= pre.pageSetup.slideWidth
    @height ||= pre.pageSetup.slideHeight
    sl = pre.slides.add(
      'Index' => pre.slides.count + 1,
      'Layout' => PowerPoint::PpLayoutBlank)
    tb = sl.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)
    sr = sl.shapes.range(1)
    sr.distribute(MsoDistributeVertically, true)
    [sl, tb, tf, tr]
  end

  def fit_font_size(width, height, text)
    (width * 1.8 / (text.map { |s| s.size } << 1).max).to_i
  end
end

if $0 == __FILE__
  file = File.new(ARGV[0])
  elements = FreeMind.new(file).elements
  PowerPoint.new do |app|
    pre = app.presentations.add
    elements.each do |e|
      puts e
      app.monta_method(pre, e)
    end
  end
end

freemind.rb

require 'rexml/document'
require 'kconv'

class FreeMind
  attr_reader :elements

  def initialize(file = nil)
    @elements = []
    parse_file(file) if file
  end

  def parse_file(file)
    doc = REXML::Document.new file
    node(doc.elements["/map"])
  end

  def node(doc)
    doc.elements.each('node') { |e|
      @elements << e.attributes['TEXT'].tosjis
      node(e)
    }
  end
end