public void CreatesCorrectly(string startHex, string endHex, int startInt, int endInt, int codeLength) { var range = new CodespaceRange(GetHexBytes(startHex.ToCharArray()), GetHexBytes(endHex.ToCharArray())); Assert.Equal(startInt, range.StartInt); Assert.Equal(endInt, range.EndInt); Assert.Equal(codeLength, range.CodeLength); }
public void MatchesCodeInRangeTrue() { var start = GetHexBytes('0', 'A'); var end = GetHexBytes('8', '0'); var codespace = new CodespaceRange(start, end); var matches = codespace.Matches(GetHexBytes('5', 'A')); Assert.True(matches); }
public void MatchesCodeHigherThanEndFalse() { var start = GetHexBytes('0', 'A'); var end = GetHexBytes('8', '0'); var codespace = new CodespaceRange(start, end); var matches = codespace.Matches(GetHexBytes('9', '6')); Assert.False(matches); }
public void MatchesCodeWrongLengthFalse() { var start = GetHexBytes('0', 'A'); var end = GetHexBytes('8', '0'); var codespace = new CodespaceRange(start, end); var matches = codespace.Matches(GetHexBytes('6', '9', '0', '1')); Assert.False(matches); }
public void IsFullMatchCodeIsNullThrows() { var start = GetHexBytes('0', 'A'); var end = GetHexBytes('8', '0'); var codespace = new CodespaceRange(start, end); Action action = () => codespace.IsFullMatch(null, 2); Assert.Throws <ArgumentNullException>(action); }
/** * This will add a codespace range. * * @param range A single codespace range. */ public void AddCodespaceRange( CodespaceRange range ) { codeSpaceRanges.Add( range ); }
/** * This will parse the stream and create a cmap object. * * @param input The CMAP stream to parse. * @return The parsed stream as a java object. * * @throws IOException If there is an error parsing the stream. */ public CMap Parse( Stream input ) { PushbackStream cmapStream = new PushbackStream( input ); CMap result = new CMap(); Object previousToken = null; Object token = null; while ( (token = ParseNextToken( cmapStream )) != null ) { if ( token is Operator ) { Operator op = (Operator)token; if ( op.op.Equals( BEGIN_CODESPACE_RANGE ) ) { IConvertible cosCount = (IConvertible)previousToken; for ( int j=0; j<cosCount.ToInt32(CultureInfo.InvariantCulture); j++ ) { byte[] startRange = (byte[])ParseNextToken( cmapStream ); byte[] endRange = (byte[])ParseNextToken( cmapStream ); CodespaceRange range = new CodespaceRange(); range.SetStart( startRange ); range.SetEnd( endRange ); result.AddCodespaceRange( range ); } } else if ( op.op.Equals( BEGIN_BASE_FONT_CHAR ) ) { IConvertible cosCount = (IConvertible)previousToken; for ( int j=0; j<cosCount.ToInt32(CultureInfo.InvariantCulture); j++ ) { byte[] inputCode = (byte[])ParseNextToken( cmapStream ); Object nextToken = ParseNextToken( cmapStream ); if ( nextToken is byte[] ) { byte[] bytes = (byte[])nextToken; String value = CreateStringFromBytes( bytes ); result.AddMapping( inputCode, value ); } else if ( nextToken is LiteralName ) { result.AddMapping( inputCode, ((LiteralName)nextToken).name ); } else { throw new IOException(MessageLocalization.GetComposedMessage("error.parsing.cmap.beginbfchar.expected.cosstring.or.cosname.and.not.1", nextToken)); } } } else if ( op.op.Equals( BEGIN_BASE_FONT_RANGE ) ) { IConvertible cosCount = (IConvertible)previousToken; for ( int j=0; j<cosCount.ToInt32(CultureInfo.InvariantCulture); j++ ) { byte[] startCode = (byte[])ParseNextToken( cmapStream ); byte[] endCode = (byte[])ParseNextToken( cmapStream ); Object nextToken = ParseNextToken( cmapStream ); IList<byte[]> array = null; byte[] tokenBytes = null; if ( nextToken is IList<byte[]> ) { array = (IList<byte[]>)nextToken; tokenBytes = array[0]; } else { tokenBytes = (byte[])nextToken; } String value = null; int arrayIndex = 0; bool done = false; while ( !done ) { if ( Compare( startCode, endCode ) >= 0 ) { done = true; } value = CreateStringFromBytes( tokenBytes ); result.AddMapping( startCode, value ); Increment( startCode ); if ( array == null ) { Increment( tokenBytes ); } else { arrayIndex++; if ( arrayIndex < array.Count ) { tokenBytes = array[arrayIndex]; } } } } } } previousToken = token; } return result; }