Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the License. You may obtain a copy of the License at
limitations under the License.
==================================================================== */

namespace NPOI.SS.UserModel
namespace NPOI.Common.UserModel.Fonts
{


Expand Down
15 changes: 15 additions & 0 deletions main/Common/UserModel/Fonts/FontFacet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.Common.UserModel.Fonts
{
public interface FontFacet
{
int Weight { get; set; }
bool IsItalic { get; set; }
object GetFontData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the License. You may obtain a copy of the License at
limitations under the License.
==================================================================== */

namespace NPOI.SS.UserModel
namespace NPOI.Common.UserModel.Fonts
{

/**
Expand All @@ -33,26 +33,25 @@ public class FontFamily
public static readonly FontFamily SCRIPT = new FontFamily(4);
public static readonly FontFamily DECORATIVE = new FontFamily(5);

private int family;
private int nativeId;

private FontFamily(int value)
{
family = value;
nativeId = value;
}

/**
* Returns index of this font family
*
* @return index of this font family
*/
public int Value
public int NativeId
{
get
{
return family;
return nativeId;
}
}

public static FontFamily ValueOf(int family)
{
switch(family)
Expand Down
173 changes: 173 additions & 0 deletions main/Common/UserModel/Fonts/FontGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using NPOI.Util;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.Common.UserModel.Fonts
{
public class FontGroup
{
/** type for latin charset (default) - also used for unicode fonts like MS Arial Unicode */
public static readonly FontGroup LATIN = new FontGroup(1);
/** type for east asian charsets - usually set as fallback for the latin font, e.g. something like MS Gothic or MS Mincho */
public static readonly FontGroup EAST_ASIAN = new FontGroup(2);
/** type for symbol fonts */
public static readonly FontGroup SYMBOL = new FontGroup(3);
/** type for complex scripts - see https://msdn.microsoft.com/en-us/library/windows/desktop/dd317698 */
public static readonly FontGroup COMPLEX_SCRIPT = new FontGroup(4);

private static Dictionary<int,Range> UCS_RANGES=null;

static FontGroup()
{
UCS_RANGES = new Dictionary<int, Range>();
UCS_RANGES.Add(0x0000, new Range(0x007F, LATIN));
UCS_RANGES.Add(0x0080, new Range(0x00A6, LATIN));
UCS_RANGES.Add(0x00A9, new Range(0x00AF, LATIN));
UCS_RANGES.Add(0x00B2, new Range(0x00B3, LATIN));
UCS_RANGES.Add(0x00B5, new Range(0x00D6, LATIN));
UCS_RANGES.Add(0x00D8, new Range(0x00F6, LATIN));
UCS_RANGES.Add(0x00F8, new Range(0x058F, LATIN));
UCS_RANGES.Add(0x0590, new Range(0x074F, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x0780, new Range(0x07BF, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x0900, new Range(0x109F, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x10A0, new Range(0x10FF, LATIN));
UCS_RANGES.Add(0x1200, new Range(0x137F, LATIN));
UCS_RANGES.Add(0x13A0, new Range(0x177F, LATIN));
UCS_RANGES.Add(0x1D00, new Range(0x1D7F, LATIN));
UCS_RANGES.Add(0x1E00, new Range(0x1FFF, LATIN));
UCS_RANGES.Add(0x1780, new Range(0x18AF, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x2000, new Range(0x200B, LATIN));
UCS_RANGES.Add(0x200C, new Range(0x200F, COMPLEX_SCRIPT));
// For the quote characters in the range U+2018 - U+201E, use the East Asian font
// if the text has one of the following language identifiers:
// ii-CN, ja-JP, ko-KR, zh-CN,zh-HK, zh-MO, zh-SG, zh-TW
UCS_RANGES.Add(0x2010, new Range(0x2029, LATIN));
UCS_RANGES.Add(0x202A, new Range(0x202F, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x2030, new Range(0x2046, LATIN));
UCS_RANGES.Add(0x204A, new Range(0x245F, LATIN));
UCS_RANGES.Add(0x2670, new Range(0x2671, COMPLEX_SCRIPT));
UCS_RANGES.Add(0x27C0, new Range(0x2BFF, LATIN));
UCS_RANGES.Add(0x3099, new Range(0x309A, EAST_ASIAN));
UCS_RANGES.Add(0xD835, new Range(0xD835, LATIN));
UCS_RANGES.Add(0xF000, new Range(0xF0FF, SYMBOL));
UCS_RANGES.Add(0xFB00, new Range(0xFB17, LATIN));
UCS_RANGES.Add(0xFB1D, new Range(0xFB4F, COMPLEX_SCRIPT));
UCS_RANGES.Add(0xFE50, new Range(0xFE6F, LATIN));
// All others EAST_ASIAN
}
private int value = 0;
protected FontGroup(int value)
{
this.value = value;
}
/**
* Try to guess the font group based on the codepoint
*
* @param runText the text which font groups are to be analyzed
* @return the FontGroup
*/
public static List<FontGroupRange> GetFontGroupRanges(String runText)
{
List<FontGroupRange> ttrList = new List<FontGroupRange>();
if(string.IsNullOrEmpty(runText))
{
return ttrList;
}
FontGroupRange ttrLast = null;
int rlen = runText.Length;
for(int cp, i = 0, charCount; i < rlen; i += charCount)
{
cp = runText[i];
charCount = 1; //StringInfo.GetNextTextElementLength(runText); TODO:fix this issue

// don't switch the font group for a few default characters supposedly available in all fonts
FontGroup tt;
if(ttrLast != null)// && " \n\r".IndexOf() > -1)
{
tt = ttrLast.FontGroup;
}
else
{
tt = lookup(cp);
}

if(ttrLast == null || ttrLast.FontGroup != tt)
{
ttrLast = new FontGroupRange(tt);
ttrList.Add(ttrLast);
}
ttrLast.IncreaseLength(charCount);
}
return ttrList;
}
public static FontGroup GetFontGroupFirst(String runText)
{
return (runText == null || string.IsNullOrEmpty(runText)) ? LATIN : lookup(runText[0]);
}

private static FontGroup lookup(int codepoint)
{
// Do a lookup for a match in UCS_RANGES
Range range =UCS_RANGES.ContainsKey(codepoint) ? UCS_RANGES[codepoint]:null;
return (range != null && codepoint <= range.Upper) ? range.FontGroup : EAST_ASIAN;
}
}

public class FontGroupRange
{
private FontGroup fontGroup;
private int len = 0;

public FontGroupRange(FontGroup fontGroup)
{
this.fontGroup = fontGroup;
}

public int Length
{
get
{
return len;
}
}

public FontGroup FontGroup
{
get
{
return fontGroup;
}
}

public void IncreaseLength(int len)
{
this.len += len;
}
}

internal class Range
{
private int upper;
private FontGroup fontGroup;
public Range(int upper, FontGroup fontGroup)
{
this.upper = upper;
this.fontGroup = fontGroup;
}

public int Upper
{
get
{
return upper;
}
}
public FontGroup FontGroup {
get { return fontGroup; }
}
}
}
20 changes: 20 additions & 0 deletions main/Common/UserModel/Fonts/FontInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.Common.UserModel.Fonts
{
public interface FontInfo
{
int Index { get; set; }
string Typeface { get; set; }
FontCharset Charset { get; set; }
FontFamily Family { get; set; }

byte[] Panose { get; set; }

List<FontFacet> GetFacets();
}
}
76 changes: 76 additions & 0 deletions main/Common/UserModel/Fonts/FontPitch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.Common.UserModel.Fonts
{
public class FontPitch
{
/**
* The default pitch, which is implementation-dependent.
*/
public static readonly FontPitch DEFAULT = new FontPitch(0x00);
/**
* A fixed pitch, which means that all the characters in the font occupy the same
* width when output in a string.
*/
public static readonly FontPitch FIXED = new FontPitch(0x01);
/**
* A variable pitch, which means that the characters in the font occupy widths
* that are proportional to the actual widths of the glyphs when output in a string. For example,
* the "i" and space characters usually have much smaller widths than a "W" or "O" character.
*/
public static readonly FontPitch VARIABLE= new FontPitch(0x02);

private int nativeId;
protected FontPitch(int nativeId)
{
this.nativeId= nativeId;
}
public int NativeId {
get {
return nativeId;
}
}
public static FontPitch ValueOf(int flag)
{
switch(flag)
{
case 1:
return FIXED;
case 2:
return VARIABLE;
default:
return DEFAULT;
}
}
/**
* Combine pitch and family to native id
*
* @see <a href="https://msdn.microsoft.com/en-us/library/dd145037.aspx">LOGFONT structure</a>
*
* @param pitch The pitch-value, cannot be null
* @param family The family-value, cannot be null
*
* @return The resulting combined byte-value with pitch and family encoded into one byte
*/
public static byte GetNativeId(FontPitch pitch, FontFamily family)
{
return (byte) (pitch.NativeId | (family.NativeId << 4));
}

/**
* Get FontPitch from native id
*
* @param pitchAndFamily The combined byte value for pitch and family
*
* @return The resulting FontPitch enumeration value
*/
public static FontPitch ValueOfPitchFamily(byte pitchAndFamily)
{
return ValueOf(pitchAndFamily & 0x3);
}
}
}
44 changes: 44 additions & 0 deletions main/SL/Draw/Geom/AdjustPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Org.BouncyCastle.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.SL.Draw.Geom
{
public class AdjustPoint : AdjustPointIf
{
public string X { get; set; }

public bool IsSetX
{
get
{
return X!=null;
}
}

public string Y { get; set; }
public bool IsSetY
{
get {
return Y!=null;
}
}

public override bool Equals(object o)
{
if(this == o)
return true;
if(!(o is AdjustPoint)) return false;
AdjustPoint that = (AdjustPoint) o;
return Objects.Equals(X, that.X) &&
Objects.Equals(Y, that.Y);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
16 changes: 16 additions & 0 deletions main/SL/Draw/Geom/AdjustPointIf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.SL.Draw.Geom
{
public interface AdjustPointIf
{
string X { get; set; }
bool IsSetX { get; }
string Y { get; set; }
bool IsSetY { get; }
}
}
Loading