347 lines
9.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace CvtFont
{
// <Font Family="Prestige Elite Tall" Size="10" Style="NONE" />
public static class CvtFont
{
public const int ELITE = 0;
public const int PICA = 1;
public const int LN_PRN = 2;
public const int CONDENSE = 3;
public const int SANSERIF = 4;
public const int PICA12 = 5;
public const int PROPORTIONAL = 6;
public const int PROPT12 = 7;
public const int HVLPT18 = 8;
public const int HVLPT25 = 9;
public const int SPECIALCHARS = 10;
public const int PT14 = 11;
public const int SANSERIF14 = 12;
public const int SANSERIF17 = 13;
public const int HVLPT12 = 14;
public const int NARRATOR = 15;
public const int MEDUPUNIVERS = 16;
public const int LGUPMED16 = 17;
/* Old name for PROPT10: public const int PT12BOLD=18 */
public const int PROPT10 = 18;
public const int LG1275HP4SI = 19;
public const int HVLPT10 = 20;
public const int HVLPT8 = 21;
public const int HVLPT14 = 22;
public const int SANSERIF25 = 23;
public const int EYECHART = 24;
public const int TIMES11 = 25;
public const int SANSCOND = 26;
private static string [] OldNames = {
"Elite",
"Pica",
"LnPrn",
"Condense",
"SanSerif",
"Pica12",
"Proportional",
"Propt12",
"HvlPt18",
"HvlPt25",
"SpecialChars",
"Pt14",
"SanSerif14",
"SanSerif17",
"HvlPt12",
"Narrator",
"MedUpUnivers",/* this font is not used */
"LgUpMed16",
"Propt10",
"Lg1275Hp4Si",
"HvlPt10",
"HvlPt8",
"HvlPt14",
"SanSerif25",
"EyeChart",
"Times11",
"SansCond",
"BigScript"
};
private static string[] NewXML = {
"<Font Family=\"Prestige Elite Tall\" Size=\"10\"/>",
"<Font Family=\"Courier New\" Size=\"12\"/>",
"<Font Family=\"Times New Roman\" Size=\"7\"/>",
"<Font Family=\"Times New Roman\" Size=\"7\"/>",
"<Font Family=\"Letter Gothic\" Size=\"10\"/>",
"<Font Family=\"Courier New\" Size=\"12\"/>",
"<Font Family=\"Arial\" Size=\"18\"/>",
"<Font Family=\"Arial\" Size=\"11\"/>",
"<Font Family=\"Times New Roman\" Size=\"18\"/>",
"<Font Family=\"Times New Roman\" Size=\"25\"/>",
"<Font Family=\"VolianDraw XXXXXX\" Size=\"12\"/>",
"<Font Family=\"Letter Gothic\" Size=\"12\"/>",
"<Font Family=\"Arial\" Size=\"14\"/>",
"<Font Family=\"Arial\" Size=\"17\"/>",
"<Font Family=\"Times New Roman\" Size=\"12\"/>",
"<Font Family=\"Gothic Ultra\" Size=\"12\"/>",
"<Font Family=\"NA\" Size=\"na\"/>",
"<Font Family=\"Letter Gothic Tall\" Size=\"7\"/>",
"<Font Family=\"Arial\" Size=\"10\"/>",
"<Font Family=\"Letter Gothic Tall\" Size=\"10\"/>",
"<Font Family=\"Times New Roman\" Size=\"10\"/>",
"<Font Family=\"Times New Roman\" Size=\"8\"/>",
"<Font Family=\"Times New Roman\" Size=\"14\"/>",
"<Font Family=\"Arial\" Size=\"25\"/>",
"<Font Family=\"Gothic Ultra\" Size=\"14\"/>",
"<Font Family=\"Times New Roman\" Size=\"11\"/>",
"<Font Family=\"Letter Gothic\" Size=\"7\"/>",
"<Font Family=\"VolianScript\" Size=\"32\"/>"
};
private static string[] NewFamily = {
"Prestige Elite Tall",
"Courier New",
"Times New Roman",
"Times New Roman",
"Letter Gothic",
"Courier New",
"Arial",
"Arial",
"Times New Roman",
"Times New Roman",
"VolianDraw XXXXXX",
"Letter Gothic",
"Arial",
"Arial",
"Times New Roman",
"Gothic Ultra",
"NA",
"Letter Gothic Tall",
"Arial",
"Letter Gothic Tall",
"Times New Roman",
"Times New Roman",
"Times New Roman",
"Arial",
"Gothic Ultra",
"Times New Roman",
"Letter Gothic",
"VolianScript"
};
private static int[] NewSize = {
10,
12,
7,
7,
10,
12,
18,
11,
18,
25,
12,
12,
14,
17,
12,
12,
0,
7,
10, /* PROPT10 - NSP & TUEC - change from 0 to 10 */
//10,
10,
8,
14,
25,
14,
11,
7,
32
};
/* The following array is not used for the migration. It is here to capture the
* values. Note that their was a difference in values in 16-bit for some of the fonts,
* as compared to the CPIS below. These fonts are PICA12, PROPT10 (PT12BOLD), HVLPT10,
* HVLPT8, HVLPT14. This was causing an incorrect results on placement of some of pagelist
* items in 16bit. What this means is that some of the 32bit will not compare identically
* with 16bit output.
*/
private static float[] PrintPitch = {
12, //ELITE
10, //PICA
16.66F, //LN_PRN
16.67F, //CONDENSE
12, //SANSERIF
12, //PICA12
10, //PROPORTIONAL
10, //PROPT12
12, //HVLPT18
12, //HVLPT25
10, //SPECIALCHARS
10, //PT14
12, //SANSERIF14
12, //SANSERIF17
12, //HVLPT12
10, //NARRATOR
16.67F, //MEDUPUNIVERS
16.67F, //LGUPMED16
10, //PROPT10
12, //LG1275HP4SI
12, //HVLPT10
12, //HVLPT8
12, //HVLPT14
12, //SANSERIF25
8.11F, //EYECHART
12, //TIMES11
16.67F, //SANSCOND
8 //VOLIANSCRIPT??
};
private static float[] CPIS = {
12, // ELITE
10, // PICA
16.66F, // LN_PRN
16.665F, // CONDENSE
12, // SANSERIF
10, // PICA12
10, // PROPORTIONAL
10, // PROPT12
12, // HVLPT18
12, // HVLPT25
10, // SPECIALCHARS
10, // PT14
12, // SANSERIF14
12, // SANSERIF17
12, // HVLPT12
10, // NARRATOR
16.67F, // MEDUPUNIVERS - medium upright univers fonts (HP3 internal)
16.67F, // LGUPMED16 - Letter Gothic Upright Medium 16.67
12, // PT12BOLD
12.50F, // LG1275HP4SI
10, // HVLPT10
8, // HVLPT8
14, // HVLP14
12, // SANSERIF25
8, // EYECHART
12, // TIMES11
16.665F // SANSCOND
};
private static float[] CPISBadPICA12 = {
12, // ELITE
10, // PICA
16.66F, // LN_PRN
16.665F, // CONDENSE
12, // SANSERIF
12, // PICA12
10, // PROPORTIONAL
10, // PROPT12
12, // HVLPT18
12, // HVLPT25
10, // SPECIALCHARS
10, // PT14
12, // SANSERIF14
12, // SANSERIF17
12, // HVLPT12
10, // NARRATOR
16.67F, // MEDUPUNIVERS - medium upright univers fonts (HP3 internal)
16.67F, // LGUPMED16 - Letter Gothic Upright Medium 16.67
12, // PT12BOLD
12.50F, // LG1275HP4SI
10, // HVLPT10
8, // HVLPT8
14, // HVLP14
12, // SANSERIF25
8, // EYECHART
12, // TIMES11
16.665F // SANSCOND
};
private static Dictionary<string, string> OldToNewStrings=null;
public static string ConvertToString(string oldstr)
{
if (OldToNewStrings == null) InitializeDictionary();
return OldToNewStrings[oldstr];
}
public static string ConvertToFamily(string oldstr)
{
int i = 0;
foreach (string str in OldNames)
{
if (str == oldstr) return NewFamily[i];
i++;
}
return null;
}
public static int ConvertToSize(string oldstr)
{
int i = 0;
foreach (string str in OldNames)
{
if (str == oldstr) return NewSize[i];
i++;
}
return -1;
}
//public static float GetNewSize(uint i)
//{
// return ConvertToNewSize[i&63];
//}
private static bool FontIsPropt(uint fontFace)
{
int f = (int)fontFace & 63;
switch (f)
{
case PROPORTIONAL:
case PROPT12:
case PROPT10:
case HVLPT12:
case HVLPT10:
case HVLPT8:
case HVLPT14:
case HVLPT18:
case HVLPT25:
case SANSERIF14:
case SANSERIF17:
case SANSERIF25:
case TIMES11:
return true;
default:
return false;
}
}
public static float GetCPIs(uint i)
{
if (FontIsPropt(i)) return 12;
uint j = i & 63;
if (j > CPIS.Length - 1)
return CPIS[0];
return CPIS[j];
}
public static float GetCPISBadPICA12(uint i)
{
if (FontIsPropt(i)) return 12;
uint j = i & 63;
if (j > CPISBadPICA12.Length - 1)
return CPISBadPICA12[0];
return CPISBadPICA12[j];
}
public static float GetPrintPitch(uint i)
{
if (FontIsPropt(i)) return 12;
return PrintPitch[i & 63];
}
//public static XmlElement ConvertToXML(string oldstr)
//{
// if (OldToNewStrings == null) InitializeDictionary();
// XmlElement xml = new XmlElement();
// xml.InnerXml = OldToNewStrings[oldstr];
// return xml;
//}
private static void InitializeDictionary()
{
int i = 0;
foreach (string str in OldNames)
OldToNewStrings.Add(str, NewXML[i]);
}
}
}