diff --git a/src/PdfSharp/Pdf.IO/Lexer.cs b/src/PdfSharp/Pdf.IO/Lexer.cs
index ddf78250..02656c60 100644
--- a/src/PdfSharp/Pdf.IO/Lexer.cs
+++ b/src/PdfSharp/Pdf.IO/Lexer.cs
@@ -247,20 +247,67 @@ public Symbol ScanName()
while (true)
{
char ch = AppendAndScanNextChar();
- if (IsWhiteSpace(ch) || IsDelimiter(ch) || ch == Chars.EOF)
- return _symbol = Symbol.Name;
- if (ch == '#')
- {
- ScanNextChar(true);
- char[] hex = new char[2];
- hex[0] = _currChar;
- hex[1] = _nextChar;
- ScanNextChar(true);
- // TODO Check syntax
- ch = (char)(ushort)int.Parse(new string(hex), NumberStyles.AllowHexSpecifier);
- _currChar = ch;
- }
+ if (ch == '#')
+ {
+ ScanNextChar(true);
+ char[] hex = new char[2];
+ hex[0] = _currChar;
+ hex[1] = _nextChar;
+ ScanNextChar(true);
+ // TODO Check syntax
+ ch = (char)(ushort)int.Parse(new string(hex), NumberStyles.AllowHexSpecifier);
+ _currChar = ch;
+ continue;
+ }
+
+ if (IsNameOrCommentDelimiter(ch) || ch == Chars.EOF)
+ {
+ return _symbol = Symbol.Name;
+ }
+
+ if (IsWhiteSpace(ch))
+ {
+ //TODO: Check that the white space is valid.
+ return _symbol = Symbol.Name;
+ }
+
+ //Handle invalid delimiters
+ switch (ch)
+ {
+ case '(':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ case ')':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ case '<':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ case '>':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ case '[':
+ //TODO: Not Complete
+ if (IsWhiteSpace(_nextChar) || IsDelimiter(_nextChar) || char.IsNumber(_nextChar) || _nextChar == '-' || PeekArrayKeyword())
+ {
+ return _symbol = Symbol.Name;
+ }
+ break;
+ case ']':
+ //TODO: Not Complete
+ if (IsWhiteSpace(_nextChar) || IsDelimiter(_nextChar) || _nextChar == Chars.EOF)
+ {
+ return _symbol = Symbol.Name;
+ }
+ break;
+ case '{':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ case '}':
+ //TODO: Handle invalid delimiters
+ return _symbol = Symbol.Name;
+ }
}
}
@@ -631,20 +678,22 @@ internal char ScanNextChar(bool handleCRLF)
// Treat single CR as LF.
_currChar = Chars.LF;
}
- }
+ //Console.WriteLine();
+ }
}
+ //Console.Write(_currChar);
return _currChar;
}
- /////
- ///// Resets the current token to the empty string.
- /////
- //void ClearToken()
- //{
- // _token.Length = 0;
- //}
+ /////
+ ///// Resets the current token to the empty string.
+ /////
+ //void ClearToken()
+ //{
+ // _token.Length = 0;
+ //}
- bool PeekReference()
+ bool PeekReference()
{
// A Reference has the form "nnn mmm R". The implementation of the parser used a
// reduce/shift algorithm in the first place. But this case is the only one we need to
@@ -692,6 +741,39 @@ bool PeekReference()
return false;
}
+ bool PeekArrayKeyword()
+ {
+ StringBuilder token = _token;
+ int position = Position;
+ ScanNextChar(true);
+
+ //Pretty sure I want to skip any non white space
+ char ch = MoveToNonWhiteSpace();
+
+ //reset the _token
+ _token = new StringBuilder();
+
+ while (!IsWhiteSpace(ch) && !IsDelimiter(ch))
+ {
+ ch = AppendAndScanNextChar();
+ }
+
+ bool b_is_keyword = false;
+ switch (_token.ToString())
+ {
+ case "null":
+ case "true":
+ case "false":
+ b_is_keyword = true;
+ break;
+ }
+
+ Position = position;
+ _token = token;
+
+ return b_is_keyword;
+ }
+
///
/// Appends current character to the token and reads next one.
///
@@ -879,10 +961,24 @@ internal static bool IsDelimiter(char ch)
return false;
}
- ///
- /// Gets the length of the PDF output.
- ///
- public int PdfLength
+ ///
+ /// Indicates whether the specified character is a PDF delimiter character.
+ ///
+ internal static bool IsNameOrCommentDelimiter(char ch)
+ {
+ switch (ch)
+ {
+ case '/':
+ case '%':
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// Gets the length of the PDF output.
+ ///
+ public int PdfLength
{
get { return _pdfLength; }
}
diff --git a/src/PdfSharp/Pdf.IO/PdfWriter.cs b/src/PdfSharp/Pdf.IO/PdfWriter.cs
index e0499e6c..0d0585ee 100644
--- a/src/PdfSharp/Pdf.IO/PdfWriter.cs
+++ b/src/PdfSharp/Pdf.IO/PdfWriter.cs
@@ -241,7 +241,9 @@ public void Write(PdfName value)
case '(':
case ')':
case '#':
- break;
+ case '[':
+ case ']':
+ break;
default:
pdf.Append(name[idx]);