/** * * 女医ハックデータパーサ * Copyright (C) 2008 id:yuaaaa * * $Id$ */ #if PocketPC #define CrazyDraw #endif using System; using System.Collections.Generic; using System.Text; using JoyHack; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; namespace JHDrawLib { public class DrawJoyHack { private List lyr; private int _width, _height; private int _defaultFontSize; private int _timeCodeFix; //frames - set from datafile private int _timeUserFix; //frames - set from App private bool _strict; private bool _fadeinout = true; //TODO: FIXME private drawCache[] cache = new drawCache[4]; public bool _debug; private string _warning; public bool disable_cache; public bool debug { get { return this._debug; } set { this.clear_cache(); this._debug = value; } } public string warning { get { return this._warning; } private set { this._warning = value; } } public bool fadeinout { get { return this._fadeinout; } set { this.clear_cache(); this._fadeinout = value; } } public int width { get { return this._width; } set { if (value <= 0) { throw new ArgumentOutOfRangeException(); } this.clear_cache(); this._width = value; } } public int height { get { return this._height; } set { if (value <= 0) { throw new ArgumentOutOfRangeException(); } this.clear_cache(); this._height = value; } } public bool strict { get { return this._strict; } set { this._strict = value; } } public int defaultFontSize { get { return this._defaultFontSize; } set { if (value < 1 || System.Single.MaxValue < value) { throw new ArgumentOutOfRangeException(); } this.clear_cache(); this._defaultFontSize = value; } } public int timeCodeFix { get { return this._timeCodeFix; } private set { this._timeCodeFix = value; } } public int timeUserFix { get { return this._timeUserFix; } set { this._timeUserFix = value; } } public DrawJoyHack(Size size) : this(size.Width, size.Height) { } public DrawJoyHack(int width, int height) { this.lyr = new List(); this.width = width; this.height = height; this.defaultFontSize = 30; this.timeCodeFix = 0; this.timeUserFix = 0; this.debug = false; this.disable_cache = false; this.strict = false; this.warning = null; } public void clear_cache () { this.cache = new drawCache[4]; } public void load_data(string file) { this.load_data(file, Encoding.GetEncoding(932)); } public void load_data ( string file , Encoding encode ) { lyr = new List(); this.warning = null; this.clear_cache(); FileStream fs = new FileStream(file, FileMode.Open); StreamReader sr = new StreamReader(fs, encode); int showline = 0; //index 0... (all_showline-1) int all_showline = 2; // 1...4 string line; WordCond cond = new WordCond(); cond.color = new ShowColor( new Color[8] {Color.White, Color.Black, Color.Red, Color.White, Color.White, Color.Black, Color.Red, Color.White} ); #if PocketPC cond.mainfont = new WordFont( new Font("MS Gothic", this.defaultFontSize, FontStyle.Regular), StringAlignment.Near, 1.0D); cond.rubyfont = new WordFont( new Font("MS Gothic", this.defaultFontSize / 2, FontStyle.Regular), StringAlignment.Near, 1.0D); #else cond.mainfont = new WordFont( new Font("MS UI Gothic", this.defaultFontSize, FontStyle.Regular, GraphicsUnit.Pixel), StringAlignment.Near, 1.0D); cond.rubyfont = new WordFont( new Font("MS UI Gothic", this.defaultFontSize/2 , FontStyle.Regular, GraphicsUnit.Pixel), StringAlignment.Near, 1.0D); #endif Alignment align = Alignment.Default; Timecode prevphr_endtime = new Timecode(0); float height = -1; int linenum = 0; while ((line = sr.ReadLine()) != null) { linenum++; try { line = line.Replace("\r", "").Replace("\n", ""); if (line.IndexOf("") >= 0 ) { string timecodestr = line.Substring("".Length); if (timecodestr.Length == 0) { this.timeCodeFix = 0; } else if (timecodestr.Length == 8) { this.timeCodeFix = new Timecode(timecodestr).allFrames; } else if (timecodestr.Length == 9) { if (timecodestr.Substring(0, 1) == "-") { this.timeCodeFix = -(new Timecode(timecodestr.Substring(1, 8)).allFrames); } else { this.timeCodeFix = +(new Timecode(timecodestr.Substring(1, 8)).allFrames); } } else { throw new JoyHackDataException("不正なです: \"" + timecodestr + "\""); } continue; } if ( line.IndexOf("") >= 0 ) { string alignstr = line.Substring("".Length); byte align_i = byte.Parse(alignstr); if (align_i < 0 || 3 < align_i) { throw new JoyHackDataException("不正なです"); } align = (Alignment)align_i; continue; } if (line.IndexOf("