git-svn-id: http://svn.sourceforge.jp/svnroot/lipsync@8 b1f601f4-4f45-0410-8980-aecacb008692

This commit is contained in:
kbinani
2009-07-29 17:03:20 +00:00
parent 0453ea1636
commit 8ab2a598b3
49 changed files with 3567 additions and 1370 deletions

View File

@@ -429,11 +429,11 @@ namespace Boare.Lib.AppUtil {
protected override void OnSizeChanged( EventArgs e ) {
#if DEBUG
Console.WriteLine( "BSplitContainer+OnSizeChanged" );
//Console.WriteLine( "BSplitContainer+OnSizeChanged" );
//Console.WriteLine( " FixedPanel=" + FixedPanel );
//Console.WriteLine( " m_splitter_distance=" + m_splitter_distance );
Console.WriteLine( " Width=" + Width );
Console.WriteLine( " Height=" + Height );
//Console.WriteLine( " Width=" + Width );
//Console.WriteLine( " Height=" + Height );
//Console.WriteLine( " m_panel2_distance=" + m_panel2_distance );
#endif
base.OnSizeChanged( e );

View File

@@ -3,15 +3,18 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0C58B068-272F-4390-A14F-3D72AFCF3DFB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Boare.Lib.AppUtil</RootNamespace>
<AssemblyName>Boare.Lib.AppUtil</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -49,9 +52,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
@@ -74,6 +74,10 @@
<Compile Include="BitmapEx.cs" />
<Compile Include="ColorBar.cs" />
<Compile Include="CubicSpline.cs" />
<Compile Include="CursorUtil.cs" />
<Compile Include="DockPanelContainer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="InputBox.cs">
<SubType>Form</SubType>
</Compile>
@@ -81,6 +85,7 @@
<DependentUpon>InputBox.cs</DependentUpon>
</Compile>
<Compile Include="ISO639.cs" />
<Compile Include="MessageBodyEntry.cs" />
<Compile Include="Messaging.cs" />
<Compile Include="MessageBody.cs" />
<Compile Include="Misc.cs" />

View File

@@ -21,7 +21,7 @@ namespace Boare.Lib.AppUtil {
public class MessageBody {
public string lang;
public string po_header = "";
public Dictionary<string, string> list = new Dictionary<string,string>();
public Dictionary<string, MessageBodyEntry> list = new Dictionary<string, MessageBodyEntry>();
public MessageBody( string lang_ ) {
lang = lang_;
@@ -29,55 +29,81 @@ namespace Boare.Lib.AppUtil {
public MessageBody( string lang, string[] ids, string[] messages ) {
this.lang = lang;
list = new Dictionary<string, string>();
list = new Dictionary<string, MessageBodyEntry>();
for( int i = 0; i < ids.Length; i++ ) {
list.Add( ids[i], messages[i] );
list.Add( ids[i], new MessageBodyEntry( messages[i], new string[] { } ) );
}
}
public MessageBody( string lang_, string file ) {
lang = lang_;
//Dictionary<string, string> list = new Dictionary<string, string>();
po_header = "";
using ( StreamReader sr = new StreamReader( file ) ) {
while ( sr.Peek() >= 0 ) {
string msgid;
string first_line = sr.ReadLine();
string last_line = ReadTillMessageEnd( sr, first_line, "msgid", out msgid );
string[] location;
string last_line = ReadTillMessageEnd( sr, first_line, "msgid", out msgid, out location );
string msgstr;
last_line = ReadTillMessageEnd( sr, last_line, "msgstr", out msgstr );
//if ( msgid.Length > 0 && msgstr.Length > 0 ) {
string[] location_dumy;
last_line = ReadTillMessageEnd( sr, last_line, "msgstr", out msgstr, out location_dumy );
if ( msgid.Length > 0 ) {
if ( list.ContainsKey( msgid ) ) {
list[msgid] = msgstr;
list[msgid] = new MessageBodyEntry( msgstr, location );
} else {
list.Add( msgid, msgstr );
list.Add( msgid, new MessageBodyEntry( msgstr, location ) );
}
} else {
po_header = msgstr;
string[] spl = po_header.Split( new char[] { (char)0x0d, (char)0x0a }, StringSplitOptions.RemoveEmptyEntries );
po_header = "";
int count = 0;
foreach ( string line in spl ) {
string[] spl2 = line.Split( new char[] { ':' }, 2 );
if ( spl2.Length == 2 ) {
string name = spl2[0].Trim();
if ( name.ToLower() == "Content-Type".ToLower() ) {
po_header += (count == 0 ? "" : "\n") + "Content-Type: text/plain; charset=UTF-8";
} else if ( name.ToLower() == "Content-Transfer-Encoding".ToLower() ) {
po_header += (count == 0 ? "" : "\n") + "Content-Transfer-Encoding: 8bit";
} else {
po_header += (count == 0 ? "" : "\n") + line;
}
} else {
po_header += (count == 0 ? "" : "\n") + line;
}
count++;
}
}
}
}
string[] ids = new string[list.Keys.Count];
string[] msgs = new string[ids.Length];
int i = -1;
foreach ( string id in list.Keys ) {
i++;
ids[i] = id;
msgs[i] = list[ids[i]];
}
#if DEBUG
Console.WriteLine( "MessageBody..ctor; po_header=" + po_header );
#endif
}
public string GetMessage( string id ) {
if ( list.ContainsKey( id ) ) {
string ret = list[id];
string ret = list[id].Message;
if ( ret == "" ) {
return id;
} else {
return list[id].Message;
}
}
return id;
}
public MessageBodyEntry GetMessageDetail( string id ) {
if ( list.ContainsKey( id ) ) {
string ret = list[id].Message;
if ( ret == "" ) {
return new MessageBodyEntry( id, new string[] { } );
} else {
return list[id];
}
}
return id;
return new MessageBodyEntry( id, new string[] { } );
}
public void Write( string file ) {
@@ -85,19 +111,26 @@ namespace Boare.Lib.AppUtil {
if ( po_header != "" ) {
sw.WriteLine( "msgid \"\"" );
sw.WriteLine( "msgstr \"\"" );
sw.WriteLine( po_header );
string[] spl = po_header.Split( new char[] { (char)0x0d, (char)0x0a }, StringSplitOptions.RemoveEmptyEntries );
foreach ( string line in spl ) {
sw.WriteLine( "\"" + line + "\\" + "n\"" );
}
sw.WriteLine();
} else {
sw.WriteLine( "msgid \"\"" );
sw.WriteLine( "msgstr \"\"" );
sw.WriteLine( "\"Content-Type: text/plain; charset=UTF-8\\n\"" );
sw.WriteLine( "\"Content-Transfer-Encoding: 8bit\\n\"" );
sw.WriteLine( "\"Content-Type: text/plain; charset=UTF-8\\" + "n\"" );
sw.WriteLine( "\"Content-Transfer-Encoding: 8bit\\" + "n\"" );
sw.WriteLine();
}
foreach ( string key in list.Keys ) {
string skey = key.Replace( "\n", "\\n\"\n\"" );
string s = list[key].Message;
List<string> location = list[key].Location;
for ( int i = 0; i < location.Count; i++ ) {
sw.WriteLine( "#: " + location[i] );
}
sw.WriteLine( "msgid \"" + skey + "\"" );
string s = list[key];
s = s.Replace( "\n", "\\n\"\n\"" );
sw.WriteLine( "msgstr \"" + s + "\"" );
sw.WriteLine();
@@ -120,28 +153,35 @@ namespace Boare.Lib.AppUtil {
message = message.Substring( 0, message.Length - 1 );
}
private static string ReadTillMessageEnd( StreamReader sr, string first_line, string entry, out string msg ) {
private static string ReadTillMessageEnd( StreamReader sr, string first_line, string entry, out string msg, out string[] locations ) {
msg = "";
string line = first_line;
List<string> location = new List<string>();
bool entry_found = false;
if ( line.StartsWith( entry ) ) {
// 1行目がすでに"entry"の行だった場合
string dum, dum2;
SeparateEntryAndMessage( line, out dum, out dum2 );
msg += dum2;
} else {
while ( sr.Peek() >= 0 ) {
line = sr.ReadLine();
if ( line.StartsWith( "#" ) ) {
continue;
}
if ( line.StartsWith( entry ) ) {
while ( true ) {
if ( line.StartsWith( "#:" ) ) {
line = line.Substring( 2 ).Trim();
location.Add( line );
} else if ( line.StartsWith( entry ) ) {
string dum, dum2;
SeparateEntryAndMessage( line, out dum, out dum2 );
msg += dum2;
break;
}
if ( sr.Peek() >= 0 ) {
line = sr.ReadLine();
} else {
break;
}
}
}
locations = location.ToArray();
string ret = "";
while ( sr.Peek() >= 0 ) {
line = sr.ReadLine();

View File

@@ -91,6 +91,18 @@ namespace Boare.Lib.AppUtil {
s_messages.Add( new MessageBody( Path.GetFileNameWithoutExtension( file ), file ) );
}
public static MessageBodyEntry GetMessageDetail( string id ) {
if ( s_lang.Length <= 0 ) {
s_lang = "en";
}
foreach ( MessageBody mb in s_messages ) {
if ( mb.lang == s_lang ) {
return mb.GetMessageDetail( id );
}
}
return new MessageBodyEntry( id, new string[] { } );
}
public static string GetMessage( string id ) {
if ( s_lang.Length <= 0 ) {
s_lang = "en";

View File

@@ -13,16 +13,120 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Reflection;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
public static partial class Misc {
public static void ApplyContextMenuFontRecurse( ContextMenuStrip item, Font font ) {
item.Font = font;
foreach ( ToolStripItem tsi in item.Items ) {
ApplyToolStripFontRecurse( tsi, font );
}
}
public static void ApplyToolStripFontRecurse( ToolStripItem item, Font font ) {
item.Font = font;
if ( item is ToolStripMenuItem ) {
ToolStripMenuItem tsmi = (ToolStripMenuItem)item;
foreach ( ToolStripItem tsi in tsmi.DropDownItems ) {
ApplyToolStripFontRecurse( tsi, font );
}
} else if ( item is ToolStripDropDownItem ) {
ToolStripDropDownItem tsdd = (ToolStripDropDownItem)item;
foreach ( ToolStripItem tsi in tsdd.DropDownItems ) {
ApplyToolStripFontRecurse( tsi, font );
}
}
}
/// <summary>
/// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
/// </summary>
/// <param name="font"></param>
/// <returns></returns>
public static int GetStringDrawOffset( Font font ) {
int ret = 0;
string pangram = "cozy lummox gives smart squid who asks for job pen. 01234567890 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS.";
SizeF size = new SizeF();
using ( Bitmap b = new Bitmap( 1, 1 ) ) {
using ( Graphics g = Graphics.FromImage( b ) ) {
size = g.MeasureString( pangram, font );
}
}
if ( size.Height <= 0 ) {
return 0;
}
using ( Bitmap b = new Bitmap( (int)size.Width * 3, (int)size.Height * 3 ) ) {
using ( Graphics g = Graphics.FromImage( b ) ) {
g.Clear( Color.White );
g.DrawString( pangram, font, Brushes.Black, new PointF( (int)size.Width, (int)size.Height ) );
}
using ( BitmapEx b2 = new BitmapEx( b ) ) {
// 上端に最初に現れる色つきピクセルを探す
int firsty = 0;
bool found = false;
for ( int y = 0; y < b2.Height; y++ ) {
for ( int x = 0; x < b2.Width; x++ ) {
Color c = b2.GetPixel( x, y );
if ( c.R != 255 || c.G != 255 || c.B != 255 ) {
found = true;
firsty = y;
break;
}
}
if ( found ) {
break;
}
}
// 下端
int endy = b2.Height - 1;
found = false;
for ( int y = b2.Height - 1; y >= 0; y-- ) {
for ( int x = 0; x < b2.Width; x++ ) {
Color c = b2.GetPixel( x, y );
if ( c.R != 255 || c.G != 255 || c.B != 255 ) {
found = true;
endy = y;
break;
}
}
if ( found ) {
break;
}
}
int center = (firsty + endy) / 2;
ret = center - (int)size.Height;
}
}
return ret;
}
/// <summary>
/// 指定した言語コードの表す言語が、右から左へ記述する言語かどうかを調べます
/// </summary>
/// <param name="language_code"></param>
/// <returns></returns>
public static bool IsRightToLeftLanguage( string language_code ) {
language_code = language_code.ToLower();
switch ( language_code ) {
case "ar":
case "he":
case "iw":
case "fa":
case "ur":
return true;
default:
return false;
}
}
/// <summary>
/// 指定したディレクトリに作成可能な、一時ファイル名を取得します
/// </summary>
@@ -92,19 +196,19 @@ namespace Boare.Lib.AppUtil {
public static string GetExtensionFromImageFormat( ImageFormat format ) {
switch ( format.ToString().ToLower() ) {
case "bmp":
return "bmp";
return ".bmp";
case "emf":
return "emf";
return ".emf";
case "gif":
return "gif";
return ".gif";
case "jpeg":
return "jpg";
return ".jpg";
case "png":
return "png";
return ".png";
case "tiff":
return "tiff";
return ".tiff";
case "wmf":
return "wmf";
return ".wmf";
default:
return "";
@@ -169,44 +273,6 @@ namespace Boare.Lib.AppUtil {
v = imax;
}
/*public static void RgbToHsv( double r, double g, double b, out double h, out double s, out double v ) {
double tmph, imax, imin;
const double sqrt3 = 1.7320508075688772935274463415059;
const double deg2rad = 180.0 / Math.PI;
imax = Math.Max( r, Math.Max( g, b ) );
imin = Math.Min( r, Math.Min( g, b ) );
if ( imax == 0.0 ) {
h = 0;
s = 0;
v = 0;
return;
} else if ( imax == imin ) {
tmph = 0;
} else {
double x = 2.0 * r - g - b;
double y = sqrt3 * (g - b);
if ( x == 0.0 ) {
if ( y > 0.0 ) {
tmph = 90.0;
} else {
tmph = 270.0;
}
} else {
tmph = Math.Atan2( y, x );
tmph = tmph * deg2rad;
}
}
while ( tmph < 0.0 ) {
tmph = tmph + 360.0;
}
while ( tmph >= 360.0 ) {
tmph = tmph - 360.0;
}
h = tmph / 360.0;
s = (imax - imin) / imax;
v = imax;
}*/
public static Color HsvToColor( double h, double s, double v ) {
double dr, dg, db;
HsvToRgb( h, s, v, out dr, out dg, out db );
@@ -286,7 +352,7 @@ namespace Boare.Lib.AppUtil {
}
/// <summary>
/// 指定したコントロールと、その子コントロールのフォントを変更します
/// 指定したコントロールと、その子コントロールのフォントを再帰的に変更します
/// </summary>
/// <param name="c"></param>
/// <param name="font"></param>

View File

@@ -179,6 +179,7 @@ namespace Boare.Lib.AppUtil {
m_last_speed = 0f;
m_last_t = 0f;
m_shift = 0f;
timer.Enabled = true;
} else {
timer.Enabled = false;

View File

@@ -1,4 +1,17 @@
using System;
/*
* XmlSerializeWithDescription.cs
* Copyright (c) 2009 kbinani
*
* This file is part of Boare.Lib.AppUtil.
*
* Boare.Lib.AppUtil is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* Boare.Lib.AppUtil is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
@@ -41,9 +54,6 @@ namespace Boare.Lib.AppUtil {
/// フィールドおよびプロパティを、XmlItemDescription属性の文字列を付加しながらXmlシリアライズする
/// </summary>
public class XmlSerializeWithDescription {
[XmlItemDescription( "mio" )]
private string foo;
private XmlTextWriter m_writer;
private Type m_type;
@@ -69,28 +79,11 @@ namespace Boare.Lib.AppUtil {
if ( t.IsGenericType ) {
List<int> f = new List<int>();
Type list_type = f.GetType().GetGenericTypeDefinition();
#if DEBUG
Console.WriteLine( "t.GetGenericTypeDefinition().Equals( list_type )=" + t.GetGenericTypeDefinition().Equals( list_type ) );
#endif
if ( t.GetGenericTypeDefinition().Equals( list_type ) ) {
Type[] gen = t.GetGenericArguments();
#if DEBUG
Console.WriteLine( "gen.Length=" + gen.Length );
#endif
if ( gen.Length == 1 ) {
PropertyInfo count_property = t.GetProperty( "Count", typeof( int ) );
int count = (int)count_property.GetValue( obj, new object[] { } );
#if DEBUG
Console.WriteLine( "count=" + count );
Console.WriteLine( "Properties" );
foreach ( PropertyInfo pi in t.GetProperties() ) {
Console.WriteLine( " " + pi );
}
Console.WriteLine( "Methods" );
foreach ( MethodInfo mi in t.GetMethods() ) {
Console.WriteLine( " " + mi );
}
#endif
Type returntype = gen[0];
MethodInfo indexer = t.GetMethod( "get_Item", new Type[] { typeof( int ) } );
string name = "";
@@ -134,9 +127,6 @@ namespace Boare.Lib.AppUtil {
xid = (XmlItemDescription)attr[0];
}
WriteContents( fi.Name, fi.GetValue( obj ), xid );
#if DEBUG
m_writer.Flush();
#endif
}
foreach ( PropertyInfo pi in t.GetProperties() ) {
if ( !pi.CanRead | !pi.CanWrite ) {
@@ -154,9 +144,6 @@ namespace Boare.Lib.AppUtil {
xid = (XmlItemDescription)attr[0];
}
WriteContents( pi.Name, pi.GetValue( obj, new object[] { } ), xid );
#if DEBUG
m_writer.Flush();
#endif
}
}
}

View File

@@ -6,12 +6,6 @@ Boare.Lib.AppUtil.dll: *.cs bocoree.dll
gmcs $(OPT) -recurse:*.cs -unsafe+ -target:library -out:Boare.Lib.AppUtil.dll \
-r:bocoree.dll,System.Drawing,System.Windows.Forms
bocoree.dll: ../bocoree/bocoree.dll
cp ../bocoree/bocoree.dll bocoree.dll
../bocoree/bocoree.dll:
cd ../bocoree/ && $(MAKE) OPT=$(OPT)
clean:
$(RM) Boare.Lib.AppUtil.dll
$(RM) bocoree.dll