Beispiel #1
0
 internal static int ComposeIndexAndCookie(byte cookie, int attributeIndex)
 {
     InternalDebug.Assert(attributeIndex >= -1);
     return(((int)cookie << 24) + (attributeIndex + 1));
 }
        public override bool ReadMore(ref char[] buffer, ref int start, ref int current, ref int end)
        {
            InternalDebug.Assert((buffer == null && start == 0 && current == 0 && end == 0) ||
                                 (buffer == this.parseBuffer &&
                                  start == this.parseStart &&
                                  end <= this.parseEnd &&
                                  start <= current));

            int charactersProduced = this.parseEnd - end;



            if (this.parseBuffer.Length - this.parseEnd <= 1 && !this.EnsureFreeSpace() && charactersProduced == 0)
            {
                return(true);
            }

            while (!this.endOfFile)
            {
                if (this.parseBuffer.Length - this.parseEnd <= 1)
                {
                    InternalDebug.Assert(charactersProduced != 0);

                    break;
                }

                if (this.pushSource != null)
                {
                    if (this.pushChunkCount == 0)
                    {
                        InternalDebug.Assert(this.pushChunkUsed == 0);

                        if (!this.pushSource.GetInputChunk(out this.pushChunkBuffer, out this.pushChunkStart, out this.pushChunkCount, out this.endOfFile))
                        {
                            InternalDebug.Assert(0 == this.pushChunkCount);
                            break;
                        }

                        InternalDebug.Assert((this.pushChunkCount != 0) != this.endOfFile);
                    }

                    InternalDebug.Assert(this.pushChunkCount - this.pushChunkUsed != 0 || this.endOfFile);

                    if (this.pushChunkCount - this.pushChunkUsed != 0)
                    {
                        int charactersToAppend = Math.Min(this.pushChunkCount - this.pushChunkUsed, this.parseBuffer.Length - this.parseEnd - 1);

                        Buffer.BlockCopy(this.pushChunkBuffer, (this.pushChunkStart + this.pushChunkUsed) * 2, this.parseBuffer, this.parseEnd * 2, charactersToAppend * 2);

                        this.pushChunkUsed += charactersToAppend;

                        this.parseEnd += charactersToAppend;

                        this.parseBuffer[this.parseEnd] = '\0';

                        charactersProduced += charactersToAppend;

                        if (this.pushChunkCount - this.pushChunkUsed == 0)
                        {
                            this.pushSource.ReportRead(this.pushChunkCount);

                            this.pushChunkStart  = 0;
                            this.pushChunkCount  = 0;
                            this.pushChunkUsed   = 0;
                            this.pushChunkBuffer = null;
                        }
                    }
                }
                else
                {
                    int readCharactersCount = this.pullSource.Read(this.parseBuffer, this.parseEnd, this.parseBuffer.Length - this.parseEnd - 1);

                    if (readCharactersCount == 0)
                    {
                        this.endOfFile = true;
                    }
                    else
                    {
                        this.parseEnd += readCharactersCount;

                        this.parseBuffer[this.parseEnd] = '\0';

                        charactersProduced += readCharactersCount;
                    }

                    if (this.progressMonitor != null)
                    {
                        this.progressMonitor.ReportProgress();
                    }
                }
            }

            buffer = this.parseBuffer;

            if (start != this.parseStart)
            {
                current = this.parseStart + (current - start);
                start   = this.parseStart;
            }

            end = this.parseEnd;

            return(charactersProduced != 0 || this.endOfFile);
        }
Beispiel #3
0
        protected void Process(TextTokenId tokenId)
        {
            if (!started)
            {
                if (!convertFragment)
                {
                    output.OpenDocument();

                    if (injection != null && injection.HaveHead)
                    {
                        injection.Inject(true, output);
                    }
                }

                output.SetQuotingLevel(0);
                started = true;
            }

            switch (tokenId)
            {
            case TextTokenId.Text:

                OutputFragmentSimple(parser.Token);
                break;

            case TextTokenId.EncodingChange:

                if (!convertFragment)
                {
                    if (output.OutputCodePageSameAsInput)
                    {
                        var codePage = parser.Token.Argument;

                            #if DEBUG
                        Encoding newOutputEncoding;
                        // we should have already checked this in parser before reporting change
                        InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding));
                            #endif

                        output.OutputEncoding = Charset.GetEncoding(codePage);
                    }
                }
                break;

            case TextTokenId.EndOfFile:

                if (!convertFragment)
                {
                    if (injection != null && injection.HaveTail)
                    {
                        if (!output.LineEmpty)
                        {
                            output.OutputNewLine();
                        }

                        injection.Inject(false, output);
                    }

                    output.Flush();
                }
                else
                {
                    output.CloseParagraph();
                }

                endOfFile = true;

                break;
            }
        }
Beispiel #4
0
        private static uint ComposeRawValue(LengthUnits lengthUnits, int len)
        {
            switch (lengthUnits)
            {
            case LengthUnits.BaseUnits:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)len & ValueMask));

            case LengthUnits.Twips:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * (8)) & ValueMask));

            case LengthUnits.Points:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * (8 * 20)) & ValueMask));

            case LengthUnits.Picas:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * (8 * 20 * 12)) & ValueMask));

            case LengthUnits.Inches:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * (8 * 20 * 72)) & ValueMask));

            case LengthUnits.Centimeters:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * ((8 * 20 * 72 * 100) / 254)) & ValueMask));

            case LengthUnits.Millimeters:
                return(GetRawType(PropertyType.AbsLength) |
                       ((uint)(len * ((8 * 20 * 72 * 10) / 254)) & ValueMask));

            case LengthUnits.HtmlFontUnits:
                return(GetRawType(PropertyType.HtmlFontUnits) |
                       ((uint)len & ValueMask));



            case LengthUnits.Pixels:

                return(GetRawType(PropertyType.Pixels) |
                       ((uint)(len * ((8 * 20 * 72) / 120)) & ValueMask));

            case LengthUnits.Ems:
                return(GetRawType(PropertyType.Ems) |
                       ((uint)(len * (8 * 20)) & ValueMask));

            case LengthUnits.Exs:
                return(GetRawType(PropertyType.Exs) |
                       ((uint)(len * (8 * 20)) & ValueMask));

            case LengthUnits.RelativeHtmlFontUnits:
                return(GetRawType(PropertyType.RelHtmlFontUnits) |
                       ((uint)len & ValueMask));

            case LengthUnits.Percents:
                return(GetRawType(PropertyType.Percentage) |
                       ((uint)len & ValueMask));
            }

            InternalDebug.Assert(false, "invalid length unit type");
            return(0);
        }
Beispiel #5
0
            public void Commit(int count)
            {
                InternalDebug.Assert(this.buffer.Length - (this.offset + this.count) >= count);

                this.count += count;
            }
Beispiel #6
0
 public RGBT(uint red, uint green, uint blue, uint transparency)
 {
     InternalDebug.Assert(red <= 255 && green <= 255 && blue <= 255 && transparency <= 7);
     this.rawValue = (red << 16) | (green << 8) | blue | (transparency << 24);
 }
Beispiel #7
0
        // Orphaned WPL code.
#if false
        private static uint ComposeRawValue(PropertyType type, uint value)
        {
            InternalDebug.Assert(value <= ValueMask);
            return(((uint)type << TypeShift) | value);
        }
Beispiel #8
0
 public void AddLiteralTextRun(RunTextType textType, int start, int end, int literal)
 {
     InternalDebug.Assert(start == this.tailOffset);
     this.AddRun(RunType.Literal, textType, (uint)RunKind.Text, start, end, literal);
 }
Beispiel #9
0
        internal void AddSentinelRun()
        {
            InternalDebug.Assert(this.token.whole.tail + 1 <= this.token.runList.Length);

            this.token.runList[this.token.whole.tail].InitializeSentinel();
        }
Beispiel #10
0
 public void AssertCurrentRunPosition(int position)
 {
     InternalDebug.Assert(position == this.tailOffset);
 }
Beispiel #11
0
 public void AddTextRun(RunTextType textType, int start, int end)
 {
     InternalDebug.Assert(start == this.tailOffset);
     this.AddRun(RunType.Normal, textType, (uint)RunKind.Text, start, end, 0);
 }
Beispiel #12
0
 public void AssertCanAddMoreRuns(int numRuns)
 {
     InternalDebug.Assert(this.token.whole.tail + numRuns <= this.token.runList.Length);
 }
Beispiel #13
0
        public void AssertPreparedToAddMoreRuns(int numRuns)
        {
#if DEBUG
            InternalDebug.Assert(numRuns <= this.preparedForNumRuns);
#endif
        }
Beispiel #14
0
        public bool CanAddProperty()
        {
            InternalDebug.Assert(this.state == BuildStateBeforeProperty);

            return(this.cssToken.propertyTail - this.cssToken.propertyHead < this.maxProperties);
        }
Beispiel #15
0
 public RGBT(uint rawValue)
 {
     InternalDebug.Assert(rawValue <= 0x07FFFFFF);
     this.rawValue = rawValue;
 }
        public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback)
        {
            InternalDebug.Assert(!this.endOfFile);
            InternalDebug.Assert(this.encoding != null);

            if (fallback != null || this.lineModeEncoding)
            {
                byte   unsafeAsciiMask       = 0;
                byte[] unsafeAsciiMap        = null;
                uint   unsafeAsciiMapLength  = 0;
                bool   hasUnsafeUnicode      = false;
                bool   treatNonAsciiAsUnsafe = false;

                if (fallback != null)
                {
                    unsafeAsciiMap = fallback.GetUnsafeAsciiMap(out unsafeAsciiMask);
                    if (unsafeAsciiMap != null)
                    {
                        unsafeAsciiMapLength = (uint)unsafeAsciiMap.Length;
                    }

                    hasUnsafeUnicode      = fallback.HasUnsafeUnicode();
                    treatNonAsciiAsUnsafe = fallback.TreatNonAsciiAsUnsafe(this.encoding.WebName);
                }

                while (0 != count)
                {
                    for (; 0 != count && this.lineBufferCount != this.lineBuffer.Length; count--, offset++)
                    {
                        char ch = buffer[offset];

                        if (fallback != null)
                        {
                            if (((uint)ch < unsafeAsciiMapLength && (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0) ||
                                (!this.encodingCompleteUnicode && (ch >= 0x7F || ch < ' ') && this.codePageMap.IsUnsafeExtendedCharacter(ch)) ||
                                (hasUnsafeUnicode && ch >= 0x7F && (treatNonAsciiAsUnsafe || fallback.IsUnsafeUnicode(ch, this.isFirstChar))))
                            {
                                if (!fallback.FallBackChar(ch, this.lineBuffer, ref this.lineBufferCount, this.lineBuffer.Length))
                                {
                                    break;
                                }
                                this.isFirstChar = false;
                                continue;
                            }
                        }

                        this.lineBuffer[this.lineBufferCount++] = ch;
                        this.isFirstChar = false;

                        if (this.lineModeEncoding)
                        {
                            if (ch == '\n' || ch == '\r')
                            {
                                this.lineBufferLastNL = this.lineBufferCount;
                            }
                            else if (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold)
                            {
                                count--;
                                offset++;

                                break;
                            }
                        }
                    }

                    if (this.lineModeEncoding &&
                        (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold ||
                         (this.lineBufferCount > this.lineBuffer.Length - SpaceThreshold &&
                          this.lineBufferLastNL != 0)))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferLastNL, false);

                        this.lineBufferCount -= this.lineBufferLastNL;

                        if (this.lineBufferCount != 0)
                        {
                            Buffer.BlockCopy(this.lineBuffer, this.lineBufferLastNL * 2, this.lineBuffer, 0, this.lineBufferCount * 2);
                        }
                    }
                    else if (this.lineBufferCount > this.lineBuffer.Length - Math.Max(this.minCharsEncode, SpaceThreshold))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount = 0;
                    }

                    this.lineBufferLastNL = 0;
                }
            }
            else
            {
                if (count > this.minCharsEncode)
                {
                    if (this.lineBufferCount != 0)
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount  = 0;
                        this.lineBufferLastNL = 0;
                    }

                    this.EncodeBuffer(buffer, offset, count, false);
                }
                else
                {
                    InternalDebug.Assert(this.lineBufferCount + count <= this.lineBuffer.Length);

                    Buffer.BlockCopy(buffer, offset * 2, this.lineBuffer, this.lineBufferCount * 2, count * 2);
                    this.lineBufferCount += count;

                    if (this.lineBufferCount > this.lineBuffer.Length - this.minCharsEncode)
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount  = 0;
                        this.lineBufferLastNL = 0;
                    }
                }
            }
        }
Beispiel #17
0
        // Orphaned WPL code.
#if false
        public RGBT(uint red, uint green, uint blue)
        {
            InternalDebug.Assert(red <= 255 && green <= 255 && blue <= 255);
            this.rawValue = (red << 16) | (green << 8) | blue;
        }
        private void EncodeBuffer(char[] buffer, int offset, int count, bool flush)
        {
            int maxSpaceRequired = this.encoding.GetMaxByteCount(count);

            byte[] outputBuffer, directBuffer = null;
            int    outputOffset, directOffset = 0;
            int    directSpace = 0;
            bool   encodingToCache = true;

            if (this.canRestart || this.pullSink == null || this.cache.Length != 0)
            {
                this.cache.GetBuffer(maxSpaceRequired, out outputBuffer, out outputOffset);
            }
            else
            {
                this.pullSink.GetOutputBuffer(out directBuffer, out directOffset, out directSpace);

                if (directSpace >= maxSpaceRequired)
                {
                    outputBuffer = directBuffer;
                    outputOffset = directOffset;

                    encodingToCache = false;
                }
                else
                {
                    this.cache.GetBuffer(maxSpaceRequired, out outputBuffer, out outputOffset);
                }
            }

            int encodedCount = this.encoder.GetBytes(buffer, offset, count, outputBuffer, outputOffset, flush);

            if (encodingToCache)
            {
                this.cache.Commit(encodedCount);

                if (this.pullSink == null)
                {
                    if (!this.canRestart || this.restartablePushSink)
                    {
                        while (this.cache.Length != 0)
                        {
                            this.cache.GetData(out outputBuffer, out outputOffset, out int outputCount);

                            this.pushSink.Write(outputBuffer, outputOffset, outputCount);

                            this.cache.ReportRead(outputCount);

                            InternalDebug.Assert(outputCount > 0);
                        }
                    }
                }
                else
                {
                    if (!this.canRestart)
                    {
                        encodedCount = this.cache.Read(directBuffer, directOffset, directSpace);

                        this.pullSink.ReportOutput(encodedCount);
                    }
                }
            }
            else
            {
                this.pullSink.ReportOutput(encodedCount);
            }
        }
Beispiel #19
0
 private static uint ComposeRawValue(PropertyType type, int value)
 {
     InternalDebug.Assert(ValueMin <= value && value <= ValueMax);
     return(((uint)type << TypeShift) | ((uint)value & ValueMask));
 }
Beispiel #20
0
        /// <summary>
        /// Perform encoding while handling end of paragraph and line wrapping.
        /// </summary>
        /// <param name="buffer">The buffer to encode.</param>
        /// <param name="offset">The offset to start encoding at.</param>
        /// <param name="count">The number of characters to encode.</param>
        /// <param name="textMapping">The text mapping.</param>
        private void OutputNonspaceImpl(char[] buffer, int offset, int count, TextMapping textMapping)
        {
            if (count != 0)
            {
                if (textMapping != TextMapping.Unicode)
                {
                    for (int i = 0; i < count; i++)
                    {
                        this.MapAndOutputSymbolCharacter(buffer[offset++], textMapping);
                    }

                    return;
                }

                if (this.endParagraph)
                {
                    InternalDebug.Assert(this.lineLength == 0);

                    this.output.Write("\r\n");
                    this.linePosition += 2;
                    this.anyNewlines   = true;
                    this.endParagraph  = false;
                }

                if (this.lineWrapping)
                {
                    this.WrapPrepareToAppendNonspace(count);

                    if (this.breakOpportunity == 0)
                    {
                        this.FlushLine(buffer[offset]);

                        this.output.Write(buffer, offset, count, this.fallbacks ? this : null);

                        this.flushedLength += count;
                    }
                    else
                    {
                        Buffer.BlockCopy(buffer, offset * 2, this.wrapBuffer, (this.lineLength - this.flushedLength) * 2, count * 2);
                    }

                    this.lineLength += count;

                    if (this.lineLength > 2 || buffer[offset] != '-' || (count == 2 && buffer[offset + 1] != '-'))
                    {
                        this.signaturePossible = false;
                    }
                }
                else
                {
                    if (this.tailSpace != 0)
                    {
                        this.FlushTailSpace();
                    }

                    this.output.Write(buffer, offset, count, this.fallbacks ? this : null);

                    this.lineLength += count;
                }
            }
        }
Beispiel #21
0
 private static uint ComposeRawValue(MultiValueHandle handle)
 {
     InternalDebug.Assert(handle.Handle < ValueMask);
     return(GetRawType(PropertyType.MultiValue) | handle.Handle);
 }
Beispiel #22
0
        /// <summary>
        /// Wrap in preparation to append non space.
        /// </summary>
        /// <param name="count">The count.</param>
        private void WrapPrepareToAppendNonspace(int count)
        {
            InternalDebug.Assert(this.lineWrapping);
            InternalDebug.Assert(this.nextBreakOpportunity == 0 || this.nextBreakOpportunity > this.breakOpportunity);

            while (this.breakOpportunity != 0 &&
                   this.lineLength + this.tailSpace + count
                   > (this.wrapped ? this.WrapBeforePosition() : this.LongestNonWrappedParagraph()))
            {
                InternalDebug.Assert(this.breakOpportunity >= this.flushedLength);

                if (this.flushedLength == 0 && this.rfc2646)
                {
                    for (int i = 0; i < this.quotingLevel; i++)
                    {
                        this.output.Write('>');
                    }

                    if (this.quotingLevel != 0 || this.wrapBuffer[0] == '>' || this.wrapBuffer[0] == ' ')
                    {
                        this.output.Write(' ');
                    }
                }

                if (this.breakOpportunity >= this.lineLength)
                {
                    InternalDebug.Assert(this.tailSpace >= this.breakOpportunity + 1 - this.lineLength);
                    InternalDebug.Assert(this.flushedLength == this.lineLength);

                    do
                    {
                        if (this.lineLength - this.flushedLength == this.wrapBuffer.Length)
                        {
                            this.output.Write(this.wrapBuffer, 0, this.wrapBuffer.Length, this.fallbacks ? this : null);
                            this.flushedLength += this.wrapBuffer.Length;
                        }

                        this.wrapBuffer[this.lineLength - this.flushedLength] = ' ';

                        this.lineLength++;
                        this.tailSpace--;
                    }while (this.lineLength != this.breakOpportunity + 1);
                }

                this.output.Write(this.wrapBuffer, 0, this.breakOpportunity + 1 - this.flushedLength, this.fallbacks ? this : null);

                this.anyNewlines = true;
                this.output.Write("\r\n");

                this.wrapped = true;
                this.lineLengthBeforeSoftWrap += this.breakOpportunity + 1;

                this.linePosition += this.breakOpportunity + 1 + 2;
                this.lineLength   -= this.breakOpportunity + 1;

                InternalDebug.Assert(this.lineLength >= 0);

                int oldFlushedLength = this.flushedLength;
                this.flushedLength = 0;

                if (this.lineLength != 0)
                {
                    if (this.nextBreakOpportunity == 0 ||
                        this.nextBreakOpportunity - (this.breakOpportunity + 1) >= this.lineLength ||
                        this.nextBreakOpportunity - (this.breakOpportunity + 1) == 0)
                    {
                        if (this.rfc2646)
                        {
                            for (int i = 0; i < this.quotingLevel; i++)
                            {
                                this.output.Write('>');
                            }

                            if (this.quotingLevel != 0 || this.wrapBuffer[this.breakOpportunity + 1 - oldFlushedLength] == '>' || this.wrapBuffer[this.breakOpportunity + 1 - oldFlushedLength] == ' ')
                            {
                                this.output.Write(' ');
                            }
                        }

                        this.output.Write(this.wrapBuffer, this.breakOpportunity + 1 - oldFlushedLength, this.lineLength, this.fallbacks ? this : null);
                        this.flushedLength = this.lineLength;
                    }
                    else
                    {
                        Buffer.BlockCopy(this.wrapBuffer, (this.breakOpportunity + 1 - oldFlushedLength) * 2, this.wrapBuffer, 0, this.lineLength * 2);
                    }
                }

                if (this.nextBreakOpportunity != 0)
                {
                    InternalDebug.Assert(this.nextBreakOpportunity > this.breakOpportunity);

                    this.breakOpportunity = this.nextBreakOpportunity - (this.breakOpportunity + 1);

                    InternalDebug.Assert(this.breakOpportunity >= 0);
                    InternalDebug.Assert(this.breakOpportunity < this.lineLength || this.tailSpace >= this.breakOpportunity + 1 - this.lineLength);

                    if (this.breakOpportunity > this.WrapBeforePosition())
                    {
                        if (this.lineLength < this.WrapBeforePosition())
                        {
                            InternalDebug.Assert(this.tailSpace != 0);

                            this.nextBreakOpportunity = this.breakOpportunity;
                            this.breakOpportunity     = this.WrapBeforePosition();
                        }
                        else if (this.breakOpportunity > this.lineLength)
                        {
                            InternalDebug.Assert(this.tailSpace != 0);

                            this.nextBreakOpportunity = this.breakOpportunity;
                            this.breakOpportunity     = this.lineLength;
                        }
                        else
                        {
                            this.nextBreakOpportunity = 0;
                        }

                        InternalDebug.Assert(this.breakOpportunity == 0 || this.breakOpportunity < this.lineLength + this.tailSpace);
                        InternalDebug.Assert(this.nextBreakOpportunity == 0 || this.nextBreakOpportunity < this.lineLength + this.tailSpace);
                    }
                    else
                    {
                        this.nextBreakOpportunity = 0;
                    }
                }
                else
                {
                    this.breakOpportunity = 0;
                }

                InternalDebug.Assert(this.breakOpportunity == 0 || this.breakOpportunity < this.lineLength + this.tailSpace);
                InternalDebug.Assert(this.nextBreakOpportunity == 0 || this.nextBreakOpportunity < this.lineLength + this.tailSpace);
            }

            if (this.tailSpace != 0)
            {
                if (this.breakOpportunity == 0)
                {
                    InternalDebug.Assert(this.lineLength == this.flushedLength);

                    if (this.flushedLength == 0 && this.rfc2646)
                    {
                        for (int i = 0; i < this.quotingLevel; i++)
                        {
                            this.output.Write('>');
                        }

                        this.output.Write(' ');
                    }

                    this.flushedLength += this.tailSpace;
                    this.FlushTailSpace();
                }
                else
                {
                    InternalDebug.Assert(this.lineLength + this.tailSpace + count - this.flushedLength
                                         <= this.LongestNonWrappedParagraph());

                    do
                    {
                        this.wrapBuffer[this.lineLength - this.flushedLength] = ' ';

                        this.lineLength++;
                        this.tailSpace--;
                    }while (this.tailSpace != 0);
                }
            }

            InternalDebug.Assert(this.breakOpportunity == 0 || this.breakOpportunity < this.lineLength + this.tailSpace);
            InternalDebug.Assert(this.nextBreakOpportunity == 0 || this.nextBreakOpportunity < this.lineLength + this.tailSpace);
        }
Beispiel #23
0
        private static uint ComposeRawValue(PropertyType type, float value)
        {
            InternalDebug.Assert(type == PropertyType.Fractional || type == PropertyType.Percentage);

            return(GetRawType(type) | ((uint)(value * 10000.0f) & ValueMask));
        }
Beispiel #24
0
        /// <summary>
        /// Encodes the character.
        /// </summary>
        /// <param name="ch">The character to encode.</param>
        /// <param name="outputBuffer">The output buffer.</param>
        /// <param name="outputBufferCount">The output buffer count.</param>
        /// <param name="outputEnd">The output end.</param>
        /// <returns>
        /// <c>true</c> if encoding is successful; otherwise, <c>false</c>.
        /// </returns>
        bool IFallback.FallBackChar(char ch, char[] outputBuffer, ref int outputBufferCount, int outputEnd)
        {
            if (this.htmlEscape)
            {
                HtmlEntityIndex namedEntityId = 0;

                if (ch <= '>')
                {
                    if (ch == '>')
                    {
                        namedEntityId = HtmlEntityIndex.gt;
                    }
                    else if (ch == '<')
                    {
                        namedEntityId = HtmlEntityIndex.lt;
                    }
                    else if (ch == '&')
                    {
                        namedEntityId = HtmlEntityIndex.amp;
                    }
                    else if (ch == '\"')
                    {
                        namedEntityId = HtmlEntityIndex.quot;
                    }
                }
                else if ((char)0xA0 <= ch && ch <= (char)0xFF)
                {
                    namedEntityId = HtmlSupport.EntityMap[(int)ch - 0xA0];
                }

                if ((int)namedEntityId != 0)
                {
                    string strQuote = HtmlNameData.entities[(int)namedEntityId].name;

                    if (outputEnd - outputBufferCount < strQuote.Length + 2)
                    {
                        return(false);
                    }

                    outputBuffer[outputBufferCount++] = '&';
                    strQuote.CopyTo(0, outputBuffer, outputBufferCount, strQuote.Length);
                    outputBufferCount += strQuote.Length;
                    outputBuffer[outputBufferCount++] = ';';
                }
                else
                {
                    uint value = (uint)ch;
                    int  len   = (value < 0x10) ? 1 : (value < 0x100) ? 2 : (value < 0x1000) ? 3 : 4;
                    if (outputEnd - outputBufferCount < len + 4)
                    {
                        return(false);
                    }

                    outputBuffer[outputBufferCount++] = '&';
                    outputBuffer[outputBufferCount++] = '#';
                    outputBuffer[outputBufferCount++] = 'x';

                    int offset = outputBufferCount + len;
                    while (value != 0)
                    {
                        uint digit = value & 0xF;
                        outputBuffer[--offset] = (char)(digit + (digit < 10 ? '0' : 'A' - 10));
                        value >>= 4;
                    }

                    outputBufferCount += len;

                    outputBuffer[outputBufferCount++] = ';';
                }
            }
            else
            {
                string substitute = AsciiEncoderFallback.GetCharacterFallback(ch);

                if (substitute != null)
                {
                    if (outputEnd - outputBufferCount < substitute.Length)
                    {
                        return(false);
                    }

                    substitute.CopyTo(0, outputBuffer, outputBufferCount, substitute.Length);
                    outputBufferCount += substitute.Length;
                }
                else
                {
                    InternalDebug.Assert(outputEnd - outputBufferCount > 0);
                    outputBuffer[outputBufferCount++] = ch;
                }
            }

            return(true);
        }
Beispiel #25
0
        public void GetData(out byte[] outputBuffer, out int outputOffset, out int outputCount)
        {
            InternalDebug.Assert(this.headEntry != null);

            this.headEntry.GetData(out outputBuffer, out outputOffset, out outputCount);
        }
Beispiel #26
0
        /// <summary>
        /// Perform encoding.
        /// </summary>
        /// <param name="text">The text to encode.</param>
        /// <param name="offset">The offset to start encoding at.</param>
        /// <param name="length">The number of characters to encode.</param>
        /// <param name="textMapping">The text mapping.</param>
        internal void OutputNonspace(string text, int offset, int length, TextMapping textMapping)
        {
            if (textMapping != TextMapping.Unicode)
            {
                for (int i = offset; i < length; i++)
                {
                    this.MapAndOutputSymbolCharacter(text[i], textMapping);
                }

                return;
            }

            if (this.endParagraph)
            {
                InternalDebug.Assert(this.lineLength == 0);

                this.output.Write("\r\n");
                this.linePosition += 2;
                this.anyNewlines   = true;
                this.endParagraph  = false;
            }

            if (this.lineWrapping)
            {
                if (length != 0)
                {
                    this.WrapPrepareToAppendNonspace(length);

                    if (this.breakOpportunity == 0)
                    {
                        this.FlushLine(text[offset]);

                        this.output.Write(text, offset, length, this.fallbacks ? this : null);

                        this.flushedLength += length;
                    }
                    else
                    {
                        text.CopyTo(offset, this.wrapBuffer, this.lineLength - this.flushedLength, length);
                    }

                    this.lineLength += length;

                    if (this.lineLength > 2 || text[offset] != '-' || (length == 2 && text[offset + 1] != '-'))
                    {
                        this.signaturePossible = false;
                    }
                }
            }
            else
            {
                if (this.tailSpace != 0)
                {
                    this.FlushTailSpace();
                }

                this.output.Write(text, offset, length, this.fallbacks ? this : null);

                this.lineLength += length;
            }
        }
Beispiel #27
0
 public override void ReportProcessed(int processedSize)
 {
     InternalDebug.Assert(processedSize >= 0);
     progressMonitor.ReportProgress();
 }
Beispiel #28
0
        /// <summary>
        /// Perform image encoding.
        /// </summary>
        /// <param name="imageUrl">The image URL.</param>
        /// <param name="imageAltText">The image alt text.</param>
        /// <param name="wdthPixels">The image width in pixels.</param>
        /// <param name="heightPixels">The image height in pixels.</param>
        internal void OutputImage(string imageUrl, string imageAltText, int wdthPixels, int heightPixels)
        {
            if (this.imageRenderingCallback != null && this.imageRenderingCallback(imageUrl, this.RenderingPosition()))
            {
                this.OutputSpace(1);
            }
            else
            {
                if ((wdthPixels == 0 || wdthPixels >= 8) && (heightPixels == 0 || heightPixels >= 8))
                {
                    bool addSpace = this.tailSpace != 0;

                    this.OutputNonspace("[", TextMapping.Unicode);

                    if (!string.IsNullOrEmpty(imageAltText))
                    {
                        int offset = 0;
                        while (offset != imageAltText.Length)
                        {
                            int nextOffset = imageAltText.IndexOfAny(Whitespaces, offset);

                            if (nextOffset == -1)
                            {
                                InternalDebug.Assert(imageAltText.Length - offset > 0);
                                this.OutputNonspace(imageAltText, offset, imageAltText.Length - offset, TextMapping.Unicode);
                                break;
                            }

                            if (nextOffset != offset)
                            {
                                this.OutputNonspace(imageAltText, offset, nextOffset - offset, TextMapping.Unicode);
                            }

                            if (imageAltText[offset] == '\t')
                            {
                                this.OutputTabulation(1);
                            }
                            else
                            {
                                this.OutputSpace(1);
                            }

                            offset = nextOffset + 1;
                        }
                    }
                    else if (!string.IsNullOrEmpty(imageUrl))
                    {
                        if (imageUrl.Contains("/") &&
                            !imageUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
                            !imageUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                        {
                            imageUrl = "X";
                        }
                        else if (imageUrl.IndexOf(' ') != -1)
                        {
                            imageUrl = imageUrl.Replace(" ", "%20");
                        }

                        this.OutputNonspace(imageUrl, TextMapping.Unicode);
                    }
                    else
                    {
                        this.OutputNonspace("X", TextMapping.Unicode);
                    }

                    this.OutputNonspace("]", TextMapping.Unicode);

                    if (addSpace)
                    {
                        this.OutputSpace(1);
                    }
                }
            }
        }
Beispiel #29
0
        public bool IsDefinedAndOff(PropertyId id)
        {
            InternalDebug.Assert(IsFlagProperty(id));

            return(DefinedBit == ((bits >> ((id - PropertyId.FirstFlag) * 2)) & ValueAndDefinedBits));
        }
Beispiel #30
0
 internal static int ExtractIndex(int attributeIndexAndCookie)
 {
     InternalDebug.Assert((attributeIndexAndCookie & 0x00FFFFFF) - 1 >= -1);
     return((attributeIndexAndCookie & 0x00FFFFFF) - 1);
 }