ソースを参照

DocX v1.0.0.7

master
coffeycathal_cp 16年前
コミット
3d79873384

+ 31
- 0
DocX/DocX/DocX.sln ファイルの表示

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocX", "DocX\DocX.csproj", "{E863D072-AA8B-4108-B5F1-785241B37F67}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF41F5CE-8BCB-40CC-835F-54A3DB7D802F}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs08.codeplex.com/
SccLocalPath0 = .
SccProjectUniqueName1 = DocX\\DocX.csproj
SccProjectName1 = DocX
SccLocalPath1 = DocX
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

+ 10
- 0
DocX/DocX/DocX.vssscc ファイルの表示

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

+ 114
- 0
DocX/DocX/DocX/CustomProperty.cs ファイルの表示

@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Novacode
{
public class CustomProperty
{
private string name;
private object value;
private string type;
/// <summary>
/// The name of this CustomProperty.
/// </summary>
public string Name { get { return name;} }
/// <summary>
/// The value of this CustomProperty.
/// </summary>
public object Value { get { return value; } }
internal string Type { get { return type; } }
internal CustomProperty(string name, string type, string value)
{
object realValue;
switch (type)
{
case "lpwstr":
{
realValue = value;
break;
}
case "i4":
{
realValue = int.Parse(value);
break;
}
case "r8":
{
realValue = double.Parse(value);
break;
}
case "filetime":
{
realValue = DateTime.Parse(value);
break;
}
case "bool":
{
realValue = bool.Parse(value);
break;
}
default: throw new Exception();
}
this.name = name;
this.type = type;
this.value = realValue;
}
private CustomProperty(string name, string type, object value)
{
this.name = name;
this.type = type;
this.value = value;
}
/// <summary>
/// Create a new CustomProperty to hold a string.
/// </summary>
/// <param name="name">The name of this CustomProperty.</param>
/// <param name="value">The value of this CustomProperty.</param>
public CustomProperty(string name, string value) : this(name, "lpwstr", value as object) { }
/// <summary>
/// Create a new CustomProperty to hold an int.
/// </summary>
/// <param name="name">The name of this CustomProperty.</param>
/// <param name="value">The value of this CustomProperty.</param>
public CustomProperty(string name, int value) : this(name, "i4", value as object) { }
/// <summary>
/// Create a new CustomProperty to hold a double.
/// </summary>
/// <param name="name">The name of this CustomProperty.</param>
/// <param name="value">The value of this CustomProperty.</param>
public CustomProperty(string name, double value) : this(name, "r8", value as object) { }
/// <summary>
/// Create a new CustomProperty to hold a DateTime.
/// </summary>
/// <param name="name">The name of this CustomProperty.</param>
/// <param name="value">The value of this CustomProperty.</param>
public CustomProperty(string name, DateTime value) : this(name, "filetime", value.ToUniversalTime() as object) { }
/// <summary>
/// Create a new CustomProperty to hold a bool.
/// </summary>
/// <param name="name">The name of this CustomProperty.</param>
/// <param name="value">The value of this CustomProperty.</param>
public CustomProperty(string name, bool value) : this(name, "bool", value as object) { }
}
}

+ 32
- 0
DocX/DocX/DocX/DocProperty.cs ファイルの表示

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace Novacode
{
/// <summary>
/// Represents a field of type document property. This field displays the value stored in a custom property.
/// </summary>
public class DocProperty
{
internal Regex extractName = new Regex(@"DOCPROPERTY (?<name>.*) ");
internal XElement xml;
private string name;
/// <summary>
/// The custom property to display.
/// </summary>
public string Name { get { return name; } }
internal DocProperty(XElement xml)
{
this.xml = xml;
string instr = xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value;
this.name = extractName.Match(instr.Trim()).Groups["name"].Value;
}
}
}

+ 2358
- 0
DocX/DocX/DocX/DocX.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 93
- 0
DocX/DocX/DocX/DocX.csproj ファイルの表示

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E863D072-AA8B-4108-B5F1-785241B37F67}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Novacode</RootNamespace>
<AssemblyName>DocX</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<StartupObject>
</StartupObject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>StrongNameKey.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\DocX.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomProperty.cs" />
<Compile Include="DocProperty.cs" />
<Compile Include="Table.cs" />
<Compile Include="Enumerations.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Formatting.cs" />
<Compile Include="Image.cs" />
<Compile Include="Picture.cs" />
<Compile Include="Paragraph.cs" />
<Compile Include="DocX.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Run.cs" />
<Compile Include="Text.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Help\Documentation - DocX v 1.0.0.7.chm" />
<None Include="StrongNameKey.pfx" />
<EmbeddedResource Include="Resources\default_styles.xml.gz" />
<EmbeddedResource Include="Resources\styles.xml.gz" />
</ItemGroup>
<ItemGroup>
<Content Include="License\License.html" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

+ 10
- 0
DocX/DocX/DocX/DocX.csproj.vspscc ファイルの表示

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

+ 272
- 0
DocX/DocX/DocX/Enumerations.cs ファイルの表示

@@ -0,0 +1,272 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Novacode
{
public enum Script { superscript, subscript, none }
public enum Highlight { yellow, green, cyan, magenta, blue, red, darkBlue, darkCyan, darkGreen, darkMagenta, darkRed, darkYellow, darkGray, lightGray, black, none };
public enum UnderlineStyle { none, singleLine, doubleLine, thick, dotted, dottedHeavy, dash, dashedHeavy, dashLong, dashLongHeavy, dotDash, dashDotHeavy, dotDotDash, dashDotDotHeavy, wave, wavyHeavy, wavyDouble, words };
public enum StrickThrough { none, strike, doubleStrike };
public enum Misc { none, shadow, outline, outlineShadow, emboss, engrave };
public enum CapsStyle { none, caps, smallCaps };
public enum RectangleShapes
{
rect,
roundRect,
snip1Rect,
snip2SameRect,
snip2DiagRect,
snipRoundRect,
round1Rect,
round2SameRect,
round2DiagRect
};
public enum BasicShapes
{
ellipse,
triangle,
rtTriangle,
parallelogram,
trapezoid,
diamond,
pentagon,
hexagon,
heptagon,
octagon,
decagon,
dodecagon,
pie,
chord,
teardrop,
frame,
halfFrame,
corner,
diagStripe,
plus,
plaque,
can,
cube,
bevel,
donut,
noSmoking,
blockArc,
foldedCorner,
smileyFace,
heart,
lightningBolt,
sun,
moon,
cloud,
arc,
backetPair,
bracePair,
leftBracket,
rightBracket,
leftBrace,
rightBrace
};
public enum BlockArrowShapes
{
rightArrow,
leftArrow,
upArrow,
downArrow,
leftRightArrow,
upDownArrow,
quadArrow,
leftRightUpArrow,
bentArrow,
uturnArrow,
leftUpArrow,
bentUpArrow,
curvedRightArrow,
curvedLeftArrow,
curvedUpArrow,
curvedDownArrow,
stripedRightArrow,
notchedRightArrow,
homePlate,
chevron,
rightArrowCallout,
downArrowCallout,
leftArrowCallout,
upArrowCallout,
leftRightArrowCallout,
quadArrowCallout,
circularArrow
};
public enum EquationShapes
{
mathPlus,
mathMinus,
mathMultiply,
mathDivide,
mathEqual,
mathNotEqual
};
public enum FlowchartShapes
{
flowChartProcess,
flowChartAlternateProcess,
flowChartDecision,
flowChartInputOutput,
flowChartPredefinedProcess,
flowChartInternalStorage,
flowChartDocument,
flowChartMultidocument,
flowChartTerminator,
flowChartPreparation,
flowChartManualInput,
flowChartManualOperation,
flowChartConnector,
flowChartOffpageConnector,
flowChartPunchedCard,
flowChartPunchedTape,
flowChartSummingJunction,
flowChartOr,
flowChartCollate,
flowChartSort,
flowChartExtract,
flowChartMerge,
flowChartOnlineStorage,
flowChartDelay,
flowChartMagneticTape,
flowChartMagneticDisk,
flowChartMagneticDrum,
flowChartDisplay
};
public enum StarAndBannerShapes
{
irregularSeal1,
irregularSeal2,
star4,
star5,
star6,
star7,
star8,
star10,
star12,
star16,
star24,
star32,
ribbon,
ribbon2,
ellipseRibbon,
ellipseRibbon2,
verticalScroll,
horizontalScroll,
wave,
doubleWave
};
public enum CalloutShapes
{
wedgeRectCallout,
wedgeRoundRectCallout,
wedgeEllipseCallout,
cloudCallout,
borderCallout1,
borderCallout2,
borderCallout3,
accentCallout1,
accentCallout2,
accentCallout3,
callout1,
callout2,
callout3,
accentBorderCallout1,
accentBorderCallout2,
accentBorderCallout3
};
/// <summary>
/// Text alignment of a paragraph
/// </summary>
public enum Alignment
{
/// <summary>
/// Align text to the left.
/// </summary>
left,
/// <summary>
/// Center text.
/// </summary>
center,
/// <summary>
/// Align text to the right.
/// </summary>
right,
/// <summary>
/// Align text to both the left and right margins, adding extra space between words as necessary.
/// </summary>
both
};
/// <summary>
/// Paragraph edit types
/// </summary>
internal enum EditType
{
/// <summary>
/// A ins is a tracked insertion
/// </summary>
ins,
/// <summary>
/// A del is tracked deletion
/// </summary>
del
}
/// <summary>
/// Custom property types.
/// </summary>
internal enum CustomPropertyType
{
/// <summary>
/// System.String
/// </summary>
Text,
/// <summary>
/// System.DateTime
/// </summary>
Date,
/// <summary>
/// System.Int32
/// </summary>
NumberInteger,
/// <summary>
/// System.Double
/// </summary>
NumberDecimal,
/// <summary>
/// System.Boolean
/// </summary>
YesOrNo
}
/// <summary>
/// Text types in a Run
/// </summary>
public enum RunTextType
{
/// <summary>
/// System.String
/// </summary>
Text,
/// <summary>
/// System.String
/// </summary>
DelText,
}
}

+ 32
- 0
DocX/DocX/DocX/Extensions.cs ファイルの表示

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Novacode
{
internal static class Extensions
{
internal static string ToHex(this Color source)
{
byte red = source.R;
byte green = source.G;
byte blue = source.B;
string redHex = red.ToString("X");
if (redHex.Length < 2)
redHex = "0" + redHex;
string blueHex = blue.ToString("X");
if (blueHex.Length < 2)
blueHex = "0" + blueHex;
string greenHex = green.ToString("X");
if (greenHex.Length < 2)
greenHex = "0" + greenHex;
return string.Format("{0}{1}{2}", redHex, greenHex, blueHex);
}
}
}

+ 337
- 0
DocX/DocX/DocX/Formatting.cs ファイルの表示

@@ -0,0 +1,337 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Drawing;
namespace Novacode
{
/// <summary>
/// A text formatting.
/// </summary>
public class Formatting
{
private XElement rPr;
private bool hidden;
private bool bold;
private bool italic;
private StrickThrough strikethrough;
private Script script;
private Highlight highlight;
private double? size;
private Color? fontColor;
private Color? underlineColor;
private UnderlineStyle underlineStyle;
private Misc misc;
private CapsStyle capsStyle;
private FontFamily fontFamily;
private int? percentageScale;
private int? kerning;
private int? position;
private double? spacing;
/// <summary>
/// A text formatting.
/// </summary>
public Formatting()
{
capsStyle = CapsStyle.none;
strikethrough = StrickThrough.none;
script = Script.none;
highlight = Highlight.none;
underlineStyle = UnderlineStyle.none;
misc = Misc.none;
rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
}
internal XElement Xml
{
get
{
rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
if(spacing.HasValue)
rPr.Add(new XElement(XName.Get("spacing", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), spacing.Value * 20)));
if(position.HasValue)
rPr.Add(new XElement(XName.Get("position", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), position.Value * 2)));
if (kerning.HasValue)
rPr.Add(new XElement(XName.Get("kern", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), kerning.Value * 2)));
if (percentageScale.HasValue)
rPr.Add(new XElement(XName.Get("w", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), percentageScale)));
if(fontFamily != null)
rPr.Add(new XElement(XName.Get("rFonts", DocX.w.NamespaceName), new XAttribute(XName.Get("ascii", DocX.w.NamespaceName), fontFamily.Name)));
if(hidden)
rPr.Add(new XElement(XName.Get("vanish", DocX.w.NamespaceName)));
if (bold)
rPr.Add(new XElement(XName.Get("b", DocX.w.NamespaceName)));
if (italic)
rPr.Add(new XElement(XName.Get("i", DocX.w.NamespaceName)));
switch (underlineStyle)
{
case UnderlineStyle.none:
break;
case UnderlineStyle.singleLine:
rPr.Add(new XElement(XName.Get("u", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), "single")));
break;
case UnderlineStyle.doubleLine:
rPr.Add(new XElement(XName.Get("u", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), "double")));
break;
default:
rPr.Add(new XElement(XName.Get("u", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), underlineStyle.ToString())));
break;
}
if(underlineColor.HasValue)
{
// If an underlineColor has been set but no underlineStyle has been set
if (underlineStyle == UnderlineStyle.none)
{
// Set the underlineStyle to the default
underlineStyle = UnderlineStyle.singleLine;
rPr.Add(new XElement(XName.Get("u", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), "single")));
}
rPr.Element(XName.Get("u", DocX.w.NamespaceName)).Add(new XAttribute(XName.Get("color", DocX.w.NamespaceName), underlineColor.Value.ToHex()));
}
switch (strikethrough)
{
case StrickThrough.none:
break;
case StrickThrough.strike:
rPr.Add(new XElement(XName.Get("strike", DocX.w.NamespaceName)));
break;
case StrickThrough.doubleStrike:
rPr.Add(new XElement(XName.Get("dstrike", DocX.w.NamespaceName)));
break;
default:
break;
}
switch (script)
{
case Script.none:
break;
default:
rPr.Add(new XElement(XName.Get("vertAlign", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), script.ToString())));
break;
}
if (size.HasValue)
{
rPr.Add(new XElement(XName.Get("sz", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), (size * 2).ToString())));
rPr.Add(new XElement(XName.Get("szCs", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), (size * 2).ToString())));
}
if(fontColor.HasValue)
rPr.Add(new XElement(XName.Get("color", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), fontColor.Value.ToHex())));
switch (highlight)
{
case Highlight.none:
break;
default:
rPr.Add(new XElement(XName.Get("highlight", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), highlight.ToString())));
break;
}
switch (capsStyle)
{
case CapsStyle.none:
break;
default:
rPr.Add(new XElement(XName.Get(capsStyle.ToString(), DocX.w.NamespaceName)));
break;
}
switch (misc)
{
case Misc.none:
break;
case Misc.outlineShadow:
rPr.Add(new XElement(XName.Get("outline", DocX.w.NamespaceName)));
rPr.Add(new XElement(XName.Get("shadow", DocX.w.NamespaceName)));
break;
case Misc.engrave:
rPr.Add(new XElement(XName.Get("imprint", DocX.w.NamespaceName)));
break;
default:
rPr.Add(new XElement(XName.Get(misc.ToString(), DocX.w.NamespaceName)));
break;
}
return rPr;
}
}
/// <summary>
/// This formatting will apply Bold.
/// </summary>
public bool Bold { get { return bold; } set { bold = value;} }
/// <summary>
/// This formatting will apply Italic.
/// </summary>
public bool Italic { get { return Italic; } set { italic = value; } }
/// <summary>
/// This formatting will apply StrickThrough.
/// </summary>
public StrickThrough StrikeThrough { get { return strikethrough; } set { strikethrough = value; } }
/// <summary>
/// The script that this formatting should be, normal, superscript or subscript.
/// </summary>
public Script Script { get { return script; } set { script = value; } }
/// <summary>
/// The Size of this text, must be between 0 and 1638.
/// </summary>
public double? Size
{
get { return size; }
set
{
double? temp = value * 2;
if (temp - (int)temp == 0)
{
if(value > 0 && value < 1639)
size = value;
else
throw new ArgumentException("Size", "Value must be in the range 0 - 1638");
}
else
throw new ArgumentException("Size", "Value must be either a whole or half number, examples: 32, 32.5");
}
}
/// <summary>
/// Percentage scale must be one of the following values 200, 150, 100, 90, 80, 66, 50 or 33.
/// </summary>
public int? PercentageScale
{
get { return percentageScale; }
set
{
if ((new int?[] { 200, 150, 100, 90, 80, 66, 50, 33 }).Contains(value))
percentageScale = value;
else
throw new ArgumentOutOfRangeException("PercentageScale", "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33");
}
}
/// <summary>
/// The Kerning to apply to this text must be one of the following values 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72.
/// </summary>
public int? Kerning
{
get { return kerning; }
set
{
if(new int?[] {8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72}.Contains(value))
kerning = value;
else
throw new ArgumentOutOfRangeException("Kerning", "Value must be one of the following: 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48 or 72");
}
}
/// <summary>
/// Text position must be in the range (-1585 - 1585).
/// </summary>
public int? Position
{
get { return position; }
set
{
if (value > -1585 && value < 1585)
position = value;
else
throw new ArgumentOutOfRangeException("Position", "Value must be in the range -1585 - 1585");
}
}
/// <summary>
/// Text spacing must be in the range (-1585 - 1585).
/// </summary>
public double? Spacing
{
get { return spacing; }
set
{
double? temp = value * 20;
if (temp - (int)temp == 0)
{
if (value > -1585 && value < 1585)
spacing = value;
else
throw new ArgumentException("Spacing", "Value must be in the range: -1584 - 1584");
}
else
throw new ArgumentException("Spacing", "Value must be either a whole or acurate to one decimal, examples: 32, 32.1, 32.2, 32.9");
}
}
/// <summary>
/// The colour of the text.
/// </summary>
public Color? FontColor { get { return fontColor; } set { fontColor = value; } }
/// <summary>
/// Highlight colour.
/// </summary>
public Highlight Highlight { get { return highlight; } set { highlight = value; } }
/// <summary>
/// The Underline style that this formatting applies.
/// </summary>
public UnderlineStyle UnderlineStyle { get { return underlineStyle; } set { underlineStyle = value; } }
/// <summary>
/// The underline colour.
/// </summary>
public Color? UnderlineColor { get { return underlineColor; } set { underlineColor = value; } }
/// <summary>
/// Misc settings.
/// </summary>
public Misc Misc { get { return misc; } set { misc = value; } }
/// <summary>
/// Is this text hidden or visible.
/// </summary>
public bool Hidden { get { return hidden; } set { hidden = value; } }
/// <summary>
/// Capitalization style.
/// </summary>
public CapsStyle CapsStyle { get { return capsStyle; } set { capsStyle = value; } }
/// <summary>
/// The font familt of this formatting.
/// </summary>
/// <!--
/// Bug found and fixed by krugs525 on August 12 2009.
/// Use TFS compare to see exact code change.
/// -->
public FontFamily FontFamily { get { return fontFamily; } set { fontFamily = value; } }
}
}

バイナリ
DocX/DocX/DocX/Help/Documentation - DocX v 1.0.0.7.chm ファイルの表示


+ 33
- 0
DocX/DocX/DocX/Image.cs ファイルの表示

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO.Packaging;
namespace Novacode
{
/// <summary>
/// Represents an Image embedded in a document.
/// </summary>
public class Image
{
/// <summary>
/// A unique id which identifies this Image.
/// </summary>
private string id;
/// <summary>
/// Returns the id of this Image.
/// </summary>
public string Id
{
get {return id;}
}
internal Image(DocX document, PackageRelationship pr)
{
id = pr.Id;
}
}
}

+ 7
- 0
DocX/DocX/DocX/License/License.html ファイルの表示

@@ -0,0 +1,7 @@
<html>
<body>
<div id="licenseTextHolder" style="margin: 1em">
<span id="ctl00_ctl00_MasterContent_Content_licenseText">Microsoft Public License &#40;Ms-PL&#41;<br /><br />This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.<br /><br />1. Definitions<br /><br />The terms &#34;reproduce,&#34; &#34;reproduction,&#34; &#34;derivative works,&#34; and &#34;distribution&#34; have the same meaning here as under U.S. copyright law.<br /><br />A &#34;contribution&#34; is the original software, or any additions or changes to the software.<br /><br />A &#34;contributor&#34; is any person that distributes its contribution under this license.<br /><br />&#34;Licensed patents&#34; are a contributor&#39;s patent claims that read directly on its contribution.<br /><br />2. Grant of Rights<br /><br />&#40;A&#41; Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.<br /><br />&#40;B&#41; Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and&#47;or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.<br /><br />3. Conditions and Limitations<br /><br />&#40;A&#41; No Trademark License- This license does not grant you rights to use any contributors&#39; name, logo, or trademarks.<br /><br />&#40;B&#41; If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.<br /><br />&#40;C&#41; If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.<br /><br />&#40;D&#41; If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.<br /><br />&#40;E&#41; The software is licensed &#34;as-is.&#34; You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.</span>
</div>
</body>
</html><!-- @SortOrder 2 -->

+ 1750
- 0
DocX/DocX/DocX/Paragraph.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 399
- 0
DocX/DocX/DocX/Picture.cs ファイルの表示

@@ -0,0 +1,399 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Drawing;
using System.IO.Packaging;
namespace Novacode
{
/// <summary>
/// Represents a Picture in this document, a Picture is a customized view of an Image.
/// </summary>
public class Picture
{
private string id;
private string name;
private string descr;
private int cx, cy;
private uint rotation;
private bool hFlip, vFlip;
private object pictureShape;
// The underlying XElement which this Image wraps
internal XElement xml;
private XElement xfrm;
private XElement prstGeom;
/// <summary>
/// Create a new Picture.
/// </summary>
/// <param name="id">A unique id that identifies an Image embedded in this document.</param>
/// <param name="name">The name of this Picture.</param>
/// <param name="descr">The description of this Picture.</param>
internal Picture(DocX document, string id, string name, string descr)
{
PackagePart word_document = document.package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
PackagePart part = document.package.GetPart(word_document.GetRelationship(id).TargetUri);
this.id = id;
this.name = name;
this.descr = descr;
using (System.Drawing.Image img = System.Drawing.Image.FromStream(part.GetStream()))
{
this.cx = img.Width * 9526;
this.cy = img.Height * 9526;
}
XElement e = new XElement(DocX.w + "drawing");
xml = XElement.Parse
(string.Format(@"
<drawing xmlns = ""http://schemas.openxmlformats.org/wordprocessingml/2006/main"">
<wp:inline distT=""0"" distB=""0"" distL=""0"" distR=""0"" xmlns:wp=""http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"">
<wp:extent cx=""{0}"" cy=""{1}"" />
<wp:effectExtent l=""0"" t=""0"" r=""0"" b=""0"" />
<wp:docPr id=""1"" name=""{3}"" descr=""{4}"" />
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a=""http://schemas.openxmlformats.org/drawingml/2006/main"" noChangeAspect=""1"" />
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a=""http://schemas.openxmlformats.org/drawingml/2006/main"">
<a:graphicData uri=""http://schemas.openxmlformats.org/drawingml/2006/picture"">
<pic:pic xmlns:pic=""http://schemas.openxmlformats.org/drawingml/2006/picture"">
<pic:nvPicPr>
<pic:cNvPr id=""0"" name=""{3}"" />
<pic:cNvPicPr />
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed=""{2}"" xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships""/>
<a:stretch>
<a:fillRect />
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x=""0"" y=""0"" />
<a:ext cx=""{0}"" cy=""{1}"" />
</a:xfrm>
<a:prstGeom prst=""rect"">
<a:avLst />
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</drawing>
", cx, cy, id, name, descr));
this.xfrm =
(
from d in xml.Descendants()
where d.Name.LocalName.Equals("xfrm")
select d
).Single();
this.prstGeom =
(
from d in xml.Descendants()
where d.Name.LocalName.Equals("prstGeom")
select d
).Single();
this.rotation = xfrm.Attribute(XName.Get("rot")) == null ? 0 : uint.Parse(xfrm.Attribute(XName.Get("rot")).Value);
}
/// <summary>
/// Remove this Picture from this document.
/// </summary>
public void Remove()
{
xml.Remove();
}
/// <summary>
/// Wraps an XElement as an Image
/// </summary>
/// <param name="i">The XElement i to wrap</param>
internal Picture(XElement i)
{
this.xml = i;
this.id =
(
from e in i.Descendants()
where e.Name.LocalName.Equals("blip")
select e.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value
).Single();
this.name =
(
from e in i.Descendants()
let a = e.Attribute(XName.Get("name"))
where (a != null)
select a.Value
).First();
this.descr =
(
from e in i.Descendants()
let a = e.Attribute(XName.Get("descr"))
where (a != null)
select a.Value
).FirstOrDefault();
this.cx =
(
from e in i.Descendants()
let a = e.Attribute(XName.Get("cx"))
where (a != null)
select int.Parse(a.Value)
).First();
this.cy =
(
from e in i.Descendants()
let a = e.Attribute(XName.Get("cy"))
where (a != null)
select int.Parse(a.Value)
).First();
this.xfrm =
(
from d in i.Descendants()
where d.Name.LocalName.Equals("xfrm")
select d
).Single();
this.prstGeom =
(
from d in i.Descendants()
where d.Name.LocalName.Equals("prstGeom")
select d
).Single();
this.rotation = xfrm.Attribute(XName.Get("rot")) == null ? 0 : uint.Parse(xfrm.Attribute(XName.Get("rot")).Value);
}
private void SetPictureShape(object shape)
{
this.pictureShape = shape;
XAttribute prst = prstGeom.Attribute(XName.Get("prst"));
if (prst == null)
prstGeom.Add(new XAttribute(XName.Get("prst"), "rectangle"));
prstGeom.Attribute(XName.Get("prst")).Value = shape.ToString();
}
/// <summary>
/// Set the shape of this Picture to one in the BasicShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the BasicShapes enumeration.</param>
public void SetPictureShape(BasicShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the RectangleShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the RectangleShapes enumeration.</param>
public void SetPictureShape(RectangleShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the BlockArrowShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the BlockArrowShapes enumeration.</param>
public void SetPictureShape(BlockArrowShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the EquationShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the EquationShapes enumeration.</param>
public void SetPictureShape(EquationShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the FlowchartShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the FlowchartShapes enumeration.</param>
public void SetPictureShape(FlowchartShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the StarAndBannerShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the StarAndBannerShapes enumeration.</param>
public void SetPictureShape(StarAndBannerShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// Set the shape of this Picture to one in the CalloutShapes enumeration.
/// </summary>
/// <param name="shape">A shape from the CalloutShapes enumeration.</param>
public void SetPictureShape(CalloutShapes shape)
{
SetPictureShape((object)shape);
}
/// <summary>
/// A unique id that identifies an Image embedded in this document.
/// </summary>
public string Id
{
get { return id; }
}
/// <summary>
/// Flip this Picture Horizontally.
/// </summary>
public bool FlipHorizontal
{
get { return hFlip; }
set
{
hFlip = value;
XAttribute flipH = xfrm.Attribute(XName.Get("flipH"));
if (flipH == null)
xfrm.Add(new XAttribute(XName.Get("flipH"), "0"));
xfrm.Attribute(XName.Get("flipH")).Value = hFlip ? "1" : "0";
}
}
/// <summary>
/// Flip this Picture Vertically.
/// </summary>
public bool FlipVertical
{
get { return vFlip; }
set
{
vFlip = value;
XAttribute flipV = xfrm.Attribute(XName.Get("flipV"));
if (flipV == null)
xfrm.Add(new XAttribute(XName.Get("flipV"), "0"));
xfrm.Attribute(XName.Get("flipV")).Value = vFlip ? "1" : "0";
}
}
/// <summary>
/// The rotation in degrees of this image, actual value = value % 360
/// </summary>
public uint Rotation
{
get { return rotation / 60000; }
set
{
rotation = (value % 360) * 60000;
XElement xfrm =
(from d in xml.Descendants()
where d.Name.LocalName.Equals("xfrm")
select d).Single();
XAttribute rot = xfrm.Attribute(XName.Get("rot"));
if(rot == null)
xfrm.Add(new XAttribute(XName.Get("rot"), 0));
xfrm.Attribute(XName.Get("rot")).Value = rotation.ToString();
}
}
/// <summary>
/// Gets or sets the name of this Image.
/// </summary>
public string Name
{
get { return name; }
set
{
name = value;
foreach (XAttribute a in xml.Descendants().Attributes(XName.Get("name")))
a.Value = name;
}
}
/// <summary>
/// Gets or sets the description for this Image.
/// </summary>
public string Description
{
get { return descr; }
set
{
descr = value;
foreach (XAttribute a in xml.Descendants().Attributes(XName.Get("descr")))
a.Value = descr;
}
}
/// <summary>
/// Get or sets the Width of this Image.
/// </summary>
public int Width
{
get { return cx / 4156; }
set
{
cx = value;
foreach (XAttribute a in xml.Descendants().Attributes(XName.Get("cx")))
a.Value = (cx * 4156).ToString();
}
}
/// <summary>
/// Get or sets the height of this Image.
/// </summary>
public int Height
{
get { return cy / 4156; }
set
{
cy = value;
foreach (XAttribute a in xml.Descendants().Attributes(XName.Get("cy")))
a.Value = (cy * 4156).ToString();
}
}
//public void Delete()
//{
// // Remove xml
// i.Remove();
// // Rebuild the image collection for this paragraph
// // Requires that every Image have a link to its paragraph
//}
}
}

+ 36
- 0
DocX/DocX/DocX/Properties/AssemblyInfo.cs ファイルの表示

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Docx")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Docx")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("16123f21-f3d1-47bb-ae9a-eb7c82c0f3c8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.7")]
[assembly: AssemblyFileVersion("1.0.0.7")]

バイナリ
DocX/DocX/DocX/Resources/default_styles.xml.gz ファイルの表示


バイナリ
DocX/DocX/DocX/Resources/styles.xml.gz ファイルの表示


+ 119
- 0
DocX/DocX/DocX/Run.cs ファイルの表示

@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Novacode
{
internal class Run
{
// A lookup for the text elements in this paragraph
Dictionary<int, Text> textLookup = new Dictionary<int, Text>();
private int startIndex;
private int endIndex;
private string text;
internal XElement xml;
/// <summary>
/// Gets the start index of this Text (text length before this text)
/// </summary>
public int StartIndex { get { return startIndex; } }
/// <summary>
/// Gets the end index of this Text (text length before this text + this texts length)
/// </summary>
public int EndIndex { get { return endIndex; } }
/// <summary>
/// The text value of this text element
/// </summary>
private string Value { set { value = text; } get { return text; } }
internal Run(int startIndex, XElement xml)
{
this.startIndex = startIndex;
this.xml = xml;
// Get the text elements in this run
IEnumerable<XElement> texts = xml.Descendants();
int start = startIndex;
// Loop through each text in this run
foreach (XElement te in texts)
{
switch (te.Name.LocalName)
{
case "tab":
{
textLookup.Add(start + 1, new Text(start, te));
text += "\t";
start++;
break;
}
case "br":
{
textLookup.Add(start + 1, new Text(start, te));
text += "\n";
start++;
break;
}
case "t": goto case "delText";
case "delText":
{
// Only add strings which are not empty
if (te.Value.Length > 0)
{
textLookup.Add(start + te.Value.Length, new Text(start, te));
text += te.Value;
start += te.Value.Length;
}
break;
}
default: break;
}
}
endIndex = start;
}
static internal XElement[] SplitRun(Run r, int index)
{
Text t = r.GetFirstTextEffectedByEdit(index);
XElement[] splitText = Text.SplitText(t, index);
XElement splitLeft = new XElement(r.xml.Name, r.xml.Attributes(), r.xml.Element(XName.Get("rPr", DocX.w.NamespaceName)), t.xml.ElementsBeforeSelf().Where(n => n.Name.LocalName != "rPr"), splitText[0]);
if(Paragraph.GetElementTextLength(splitLeft) == 0)
splitLeft = null;
XElement splitRight = new XElement(r.xml.Name, r.xml.Attributes(), r.xml.Element(XName.Get("rPr", DocX.w.NamespaceName)), splitText[1], t.xml.ElementsAfterSelf().Where(n => n.Name.LocalName != "rPr"));
if(Paragraph.GetElementTextLength(splitRight) == 0)
splitRight = null;
return
(
new XElement[]
{
splitLeft,
splitRight
}
);
}
internal Text GetFirstTextEffectedByEdit(int index)
{
foreach (int textEndIndex in textLookup.Keys)
{
if (textEndIndex > index)
return textLookup[textEndIndex];
}
if (textLookup.Last().Value.EndIndex == index)
return textLookup.Last().Value;
throw new ArgumentOutOfRangeException();
}
}
}

バイナリ
DocX/DocX/DocX/StrongNameKey.pfx ファイルの表示


+ 1203
- 0
DocX/DocX/DocX/Table.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 143
- 0
DocX/DocX/DocX/Text.cs ファイルの表示

@@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Novacode
{
internal class Text
{
private int startIndex;
private int endIndex;
private string text;
internal XElement xml;
/// <summary>
/// Gets the start index of this Text (text length before this text)
/// </summary>
public int StartIndex { get { return startIndex; } }
/// <summary>
/// Gets the end index of this Text (text length before this text + this texts length)
/// </summary>
public int EndIndex { get { return endIndex; } }
/// <summary>
/// The text value of this text element
/// </summary>
public string Value { get { return text; } }
internal Text(int startIndex, XElement e)
{
this.startIndex = startIndex;
this.xml = e;
switch (e.Name.LocalName)
{
case "t":
{
goto case "delText";
}
case "delText":
{
endIndex = startIndex + e.Value.Length;
text = e.Value;
break;
}
case "br":
{
text = "\n";
endIndex = startIndex + 1;
break;
}
case "tab":
{
text = "\t";
endIndex = startIndex + 1;
break;
}
default:
{
break;
}
}
}
internal static XElement[] SplitText(Text t, int index)
{
if (index < t.startIndex || index > t.EndIndex)
throw new ArgumentOutOfRangeException("index");
XElement splitLeft = null, splitRight = null;
if (t.xml.Name.LocalName == "t" || t.xml.Name.LocalName == "delText")
{
// The origional text element, now containing only the text before the index point.
splitLeft = new XElement(t.xml.Name, t.xml.Attributes(), t.xml.Value.Substring(0, index - t.startIndex));
if (splitLeft.Value.Length == 0)
splitLeft = null;
else
PreserveSpace(splitLeft);
// The origional text element, now containing only the text after the index point.
splitRight = new XElement(t.xml.Name, t.xml.Attributes(), t.xml.Value.Substring(index - t.startIndex, t.xml.Value.Length - (index - t.startIndex)));
if (splitRight.Value.Length == 0)
splitRight = null;
else
PreserveSpace(splitRight);
}
else
{
if (index == t.StartIndex)
splitLeft = t.xml;
else
splitRight = t.xml;
}
return
(
new XElement[]
{
splitLeft,
splitRight
}
);
}
/// <summary>
/// If a text element or delText element, starts or ends with a space,
/// it must have the attribute space, otherwise it must not have it.
/// </summary>
/// <param name="e">The (t or delText) element check</param>
public static void PreserveSpace(XElement e)
{
// PreserveSpace should only be used on (t or delText) elements
if (!e.Name.Equals(DocX.w + "t") && !e.Name.Equals(DocX.w + "delText"))
throw new ArgumentException("SplitText can only split elements of type t or delText", "e");
// Check if this w:t contains a space atribute
XAttribute space = e.Attributes().Where(a => a.Name.Equals(XNamespace.Xml + "space")).SingleOrDefault();
// This w:t's text begins or ends with whitespace
if (e.Value.StartsWith(" ") || e.Value.EndsWith(" "))
{
// If this w:t contains no space attribute, add one.
if (space == null)
e.Add(new XAttribute(XNamespace.Xml + "space", "preserve"));
}
// This w:t's text does not begin or end with a space
else
{
// If this w:r contains a space attribute, remove it.
if (space != null)
space.Remove();
}
}
}
}

読み込み中…
キャンセル
保存