Skip to content

Commit

Permalink
merge: switching to word-to-dtbook pipeline script
Browse files Browse the repository at this point in the history
From this commit, the word to dtbook conversion
is now done using the DAISY Pipeline 2.0 and the
word to dtbook script.
  • Loading branch information
NPavie committed Nov 13, 2024
2 parents da97d2b + edf131b commit 97ae3f6
Show file tree
Hide file tree
Showing 527 changed files with 2,887 additions and 1,262 deletions.
8 changes: 5 additions & 3 deletions Common/DaisyAddinLib/ConverterSettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void Daisysettingsfrm_Load(object sender, EventArgs e)
{
notesNumberingStartValue.Mask = "000";

if (GlobaleSettings.PagenumStyle == "Custom")
if (GlobaleSettings.PagenumStyle == ConverterSettings.PageNumberingChoice.Enum.Custom)
{
this.radiobtn_custom.Checked = true;
}
Expand Down Expand Up @@ -274,7 +274,9 @@ private void btn_ok_Click(object sender, EventArgs e)
try
{
// Update fields
GlobaleSettings.PagenumStyle = this.radiobtn_custom.Checked ? "Custom" : "Automatic";
GlobaleSettings.PagenumStyle = this.radiobtn_custom.Checked
? ConverterSettings.PageNumberingChoice.Enum.Custom
: ConverterSettings.PageNumberingChoice.Enum.Automatic;
GlobaleSettings.CharacterStyle = this.checkbox_translate.Checked;

if (this.radiobtn_originalimage.Checked == true)
Expand Down Expand Up @@ -329,7 +331,7 @@ private void btn_ok_Click(object sender, EventArgs e)
GlobaleSettings.AzureSpeechRegion = AzureRegionDictionnary[(string)(AzureRegionValue.SelectedItem ?? "")];

// Save
GlobaleSettings.save();
GlobaleSettings.Save();
this.Close();
}
catch (Exception ex)
Expand Down
7 changes: 4 additions & 3 deletions Common/DaisyAddinLib/DaisyAddinLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
Expand Down Expand Up @@ -420,6 +421,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="DaisyTranslatorPhaseTwo.snk" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -534,13 +536,12 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="resources\about screen.png" />
</ItemGroup>
<ItemGroup>
<Reference Include="stdole, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\stdole.dll</HintPath>
<HintPath>..\..\resources\stdole.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions Common/DaisyAddinLib/GraphicalEventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void onPostProcessingStart(ConversionParameters conversion)
public void onPostProcessingSuccess(ConversionParameters conversion)
{
TryShowMessage(
"Successfully processed or converted dtbook, result stored in "
"Successfully processed or converted document, result stored in "
+ conversion.OutputPath,
true
);
Expand Down Expand Up @@ -338,7 +338,7 @@ public void onPostProcessingError(Exception errors)
e = e.InnerException;
}
AddinLogger.Error("Errors reported during conversion by DAISY Pipeline 2: \r\n" + message);
TryShowMessage("Errors reported during conversion by DAISY Pipeline 2 : " + errors.Message, true);
TryShowMessage("Errors reported during conversion by DAISY Pipeline 2 : \r\n" + message, true);
}

public void onConversionSuccess()
Expand Down
9 changes: 9 additions & 0 deletions Common/DaisyAddinLib/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1"/>
</startup>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
</configuration>
3 changes: 0 additions & 3 deletions Common/DaisyAddinLib/packages.config

This file was deleted.

298 changes: 233 additions & 65 deletions Common/DaisyConverterLib/Converter.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Common/DaisyConverterLib/ConverterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string AppDataSaveAsDAISYDirectory {



public static bool documentIsOpen(string documentPath) {
public static bool DocumentIsOpen(string documentPath) {
try {
Package pack;
pack = Package.Open(documentPath, FileMode.Open, FileAccess.ReadWrite);
Expand Down
70 changes: 59 additions & 11 deletions Common/DaisyConverterLib/ConverterSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;

namespace Daisy.SaveAsDAISY.Conversion
Expand Down Expand Up @@ -61,6 +62,11 @@ public enum Enum
{ "resize", Enum.Resize },
{ "resample", Enum.Resample},
};

public static readonly EnumDataType DataType = new EnumDataType(
Values.ToDictionary(kvp => kvp.Key.ToString(), kvp => (object)kvp.Value),
Enum.Original.ToString() // Default value is now stored here
);
}

/// <summary>
Expand Down Expand Up @@ -98,6 +104,11 @@ public enum Enum
{ "end", Enum.End },
{ "page", Enum.Page},
};

public static readonly EnumDataType DataType = new EnumDataType(
Values.ToDictionary(kvp => kvp.Key.ToString(), kvp => (object)kvp.Value),
Enum.Inline.ToString() // Default value is now stored here
);
}

/// <summary>
Expand Down Expand Up @@ -135,17 +146,54 @@ public enum Enum
{ "number", Enum.Number },
{ "none", Enum.None},
};

public static readonly EnumDataType DataType = new EnumDataType(
Values.ToDictionary(kvp => kvp.Key.ToString(), kvp => (object)kvp.Value),
Enum.None.ToString()
);
}

public static class PageNumberingChoice
{
/// <summary>
/// Possible type of page numbering computation
/// </summary>
public enum Enum
{
/// <summary>
/// Use numbers tagged with style PagenumberDAISY to insert page numbers in content
/// </summary>
Custom,
/// <summary>
/// Use word page break to compute and insert page numbers in content
/// </summary>
Automatic
}
public static readonly Dictionary<Enum, string> Values = new Dictionary<Enum, string>()
{
{ Enum.Custom, "custom" },
{ Enum.Automatic, "automatic" },
};
public static readonly Dictionary<string, Enum> Keys = new Dictionary<string, Enum>()
{
{ "custom", Enum.Custom },
{ "automatic", Enum.Automatic },
};
public static readonly EnumDataType DataType = new EnumDataType(
Values.ToDictionary(kvp => kvp.Key.ToString(), kvp => (object)kvp.Value),
Enum.Custom.ToString()
);
}

#region Private fields with default values

private string imgoption = "original";
private string imgoption = ImageOptionChoice.DataType.Value.ToString();
private string resampleValue = "96";
private string characterStyle = "False";
private string pagenumStyle = "Custom";
private string pagenumStyle = PageNumberingChoice.DataType.Value.ToString();
private string footnotesLevel = "0"; // 0 mean current paragraphe level, < 0 means parent level going upward, > 1 means absolute dtbook level
private string footnotesPosition = "inline"; // Should be inline, end, or page
private string footnotesNumbering = "none"; // should be number, none, or word
private string footnotesPosition = FootnotesPositionChoice.DataType.Value.ToString(); // Should be inline, end, or page
private string footnotesNumbering = FootnotesNumberingChoice.DataType.Value.ToString(); // should be number, none, or word
private string footnotesStartValue = "1"; // number to be used
private string footnotesNumberingPrefix = ""; // prefix to be added before the numbering
private string footnotesNumberingSuffix = ""; // suffix to be added between the number and the text
Expand All @@ -159,7 +207,7 @@ public enum Enum
/// <param name="withPrivateData">if set to true, settings that are private to users
/// (like tts keys) will also be included</param>
/// <returns></returns>
public string asXML(bool withPrivateData = false)
public string AsXML(bool withPrivateData = false)
{
return $"<Settings>" +
$"\r\n\t<PageNumbers value=\"{pagenumStyle}\" />" +
Expand Down Expand Up @@ -191,7 +239,7 @@ public void CreateDefaultSettings()
}
using (StreamWriter writer = new StreamWriter(File.Create(ConverterSettingsFile)))
{
writer.Write(asXML());
writer.Write(AsXML());
writer.Flush();
}
}
Expand All @@ -204,7 +252,7 @@ private ConverterSettings()
if (!File.Exists(ConverterSettingsFile))
{
// Save the default settings
save();
Save();
}

settingsDocument.Load(ConverterSettingsFile);
Expand All @@ -224,7 +272,7 @@ private ConverterSettings()
XmlNode PageNumbersNode = settingsDocument.SelectSingleNode("//Settings/PageNumbers");
if (PageNumbersNode != null)
{
pagenumStyle = (PageNumbersNode.Attributes["value"]?.InnerXml) ?? pagenumStyle;
pagenumStyle = ((PageNumbersNode.Attributes["value"]?.InnerXml) ?? pagenumStyle).ToLowerInvariant();
}

XmlNode FootnotesSettings = settingsDocument.SelectSingleNode("//Settings/Footnotes");
Expand Down Expand Up @@ -257,15 +305,15 @@ private ConverterSettings()
/// <summary>
/// Save the converter settings to an xml file on disk
/// </summary>
public void save()
public void Save()
{
if (!Directory.Exists(ApplicationDataFolder))
{
Directory.CreateDirectory(ApplicationDataFolder);
}
using (StreamWriter writer = new StreamWriter(File.Create(ConverterSettingsFile)))
{
writer.Write(asXML(true));
writer.Write(AsXML(true));
writer.Flush();
}
}
Expand All @@ -278,7 +326,7 @@ public void save()

public bool CharacterStyle { get => characterStyle != "False"; set => characterStyle = value ? "True" : "False"; }

public string PagenumStyle { get => pagenumStyle; set => pagenumStyle = value; }
public PageNumberingChoice.Enum PagenumStyle { get => PageNumberingChoice.Keys[pagenumStyle]; set => pagenumStyle = PageNumberingChoice.Values[value]; }

/// <summary>
/// Position of the notes relatively to the selected level <br/>
Expand Down
34 changes: 20 additions & 14 deletions Common/DaisyConverterLib/DaisyConverterLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
Expand Down Expand Up @@ -71,6 +72,7 @@
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<Prefer32Bit>false</Prefer32Bit>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release to Client%28signed%29|AnyCPU' ">
<OutputPath>bin\Release to Client%28signed%29\</OutputPath>
Expand Down Expand Up @@ -115,6 +117,7 @@
<Prefer32Bit>false</Prefer32Bit>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release to Client%28signed%29|x64'">
<OutputPath>bin\x64\Release to Client%28signed%29\</OutputPath>
Expand All @@ -128,9 +131,10 @@
<Compile Include="Converter.cs" />
<Compile Include="Events\SilentEventsHandler.cs" />
<Compile Include="Parameters\PrepopulateDaisyOutput.cs" />
<Compile Include="Pipeline\ChainedScripts\CleanedDtbookToMp3.cs" />
<Compile Include="Pipeline\ChainedScripts\CleanedDtbookToDaisy3.cs" />
<Compile Include="Pipeline\ChainedScripts\CleanedDtbookToEpub3.cs" />
<Compile Include="Pipeline\ChainedScripts\WordToMp3.cs" />
<Compile Include="Pipeline\ChainedScripts\WordToDaisy3.cs" />
<Compile Include="Pipeline\ChainedScripts\WordToEpub3.cs" />
<Compile Include="Pipeline\ChainedScripts\WordToCleanedDtbook.cs" />
<Compile Include="Pipeline\DataTypes\MapDataType.cs" />
<Compile Include="Pipeline\ParameterDataType.cs" />
<Compile Include="Pipeline\Pipeline2\Pipeline2.cs" />
Expand All @@ -139,6 +143,7 @@
<Compile Include="Pipeline\Pipeline2\Scripts\DtbookCleaner.cs" />
<Compile Include="Pipeline\Pipeline2\Scripts\DtbookToDaisy3.cs" />
<Compile Include="Pipeline\Pipeline2\Scripts\DtbookToEpub3.cs" />
<Compile Include="Pipeline\Pipeline2\Scripts\WordToDtbook.cs" />
<Compile Include="Pipeline\Script.cs" />
<Compile Include="Preprocessing\StringValidator.cs" />
<Compile Include="Preprocessing\IDocumentPreprocessor.cs" />
Expand Down Expand Up @@ -177,6 +182,7 @@
<EmbeddedResource Include="resources\source.xml" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="DaisyTranslatorPhaseTwo.snk" />
<EmbeddedResource Include="resources\dtds\dtbook-2005-3.dtd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down Expand Up @@ -247,7 +253,6 @@
<EmbeddedResource Include="resources\entities\mmlextra.ent">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down Expand Up @@ -312,15 +317,8 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="JNET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=95283358f4f60f4e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\JNET.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="JNET">
<HintPath>..\..\resources\JNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand All @@ -338,5 +336,13 @@
<Name>Localization</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net">
<Version>2.0.14</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
5 changes: 1 addition & 4 deletions Common/DaisyConverterLib/Parameters/ConversionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ public Hashtable ParametersHash

parameters.Add("CharacterStyles", GlobalSettings.CharacterStyle);

if (GlobalSettings.PagenumStyle != " ")
{
parameters.Add("Custom", GlobalSettings.PagenumStyle);
}
parameters.Add("Custom", PageNumberingChoice.Values[GlobalSettings.PagenumStyle]);
// 20220402 : adding footnotes positioning settings
// might be "page", "inline", "end" or "after"
parameters.Add("FootnotesPosition", FootnotesPositionChoice.Values[GlobalSettings.FootnotesPosition]);
Expand Down
Loading

0 comments on commit 97ae3f6

Please sign in to comment.