gfx/thebes/gfxSkipChars.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "gfxSkipChars.h"
michael@0 7
michael@0 8 void
michael@0 9 gfxSkipCharsIterator::SetOriginalOffset(int32_t aOffset)
michael@0 10 {
michael@0 11 aOffset += mOriginalStringToSkipCharsOffset;
michael@0 12 NS_ASSERTION(uint32_t(aOffset) <= mSkipChars->mCharCount,
michael@0 13 "Invalid offset");
michael@0 14
michael@0 15 mOriginalStringOffset = aOffset;
michael@0 16
michael@0 17 uint32_t rangeCount = mSkipChars->mRanges.Length();
michael@0 18 if (rangeCount == 0) {
michael@0 19 mSkippedStringOffset = aOffset;
michael@0 20 return;
michael@0 21 }
michael@0 22
michael@0 23 // at start of string?
michael@0 24 if (aOffset == 0) {
michael@0 25 mSkippedStringOffset = 0;
michael@0 26 mCurrentRangeIndex =
michael@0 27 rangeCount && mSkipChars->mRanges[0].Start() == 0 ? 0 : -1;
michael@0 28 return;
michael@0 29 }
michael@0 30
michael@0 31 // find the range that includes or precedes aOffset
michael@0 32 uint32_t lo = 0, hi = rangeCount;
michael@0 33 const gfxSkipChars::SkippedRange* ranges = mSkipChars->mRanges.Elements();
michael@0 34 while (lo < hi) {
michael@0 35 uint32_t mid = (lo + hi) / 2;
michael@0 36 if (uint32_t(aOffset) < ranges[mid].Start()) {
michael@0 37 hi = mid;
michael@0 38 } else {
michael@0 39 lo = mid + 1;
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 if (lo == rangeCount) {
michael@0 44 mCurrentRangeIndex = rangeCount - 1;
michael@0 45 } else if (uint32_t(aOffset) < ranges[lo].Start()) {
michael@0 46 mCurrentRangeIndex = lo - 1;
michael@0 47 if (mCurrentRangeIndex == -1) {
michael@0 48 mSkippedStringOffset = aOffset;
michael@0 49 return;
michael@0 50 }
michael@0 51 } else {
michael@0 52 mCurrentRangeIndex = lo;
michael@0 53 }
michael@0 54
michael@0 55 const gfxSkipChars::SkippedRange& r = ranges[mCurrentRangeIndex];
michael@0 56 if (uint32_t(aOffset) < r.End()) {
michael@0 57 mSkippedStringOffset = r.SkippedOffset();
michael@0 58 return;
michael@0 59 }
michael@0 60
michael@0 61 mSkippedStringOffset = aOffset - r.NextDelta();
michael@0 62 }
michael@0 63
michael@0 64 void
michael@0 65 gfxSkipCharsIterator::SetSkippedOffset(uint32_t aOffset)
michael@0 66 {
michael@0 67 NS_ASSERTION((mSkipChars->mRanges.IsEmpty() &&
michael@0 68 aOffset <= mSkipChars->mCharCount) ||
michael@0 69 (aOffset <= mSkipChars->LastRange().SkippedOffset() +
michael@0 70 mSkipChars->mCharCount -
michael@0 71 mSkipChars->LastRange().End()),
michael@0 72 "Invalid skipped offset");
michael@0 73 mSkippedStringOffset = aOffset;
michael@0 74
michael@0 75 uint32_t rangeCount = mSkipChars->mRanges.Length();
michael@0 76 if (rangeCount == 0) {
michael@0 77 mOriginalStringOffset = aOffset;
michael@0 78 return;
michael@0 79 }
michael@0 80
michael@0 81 uint32_t lo = 0, hi = rangeCount;
michael@0 82 const gfxSkipChars::SkippedRange* ranges = mSkipChars->mRanges.Elements();
michael@0 83 while (lo < hi) {
michael@0 84 uint32_t mid = (lo + hi) / 2;
michael@0 85 if (aOffset < ranges[mid].SkippedOffset()) {
michael@0 86 hi = mid;
michael@0 87 } else {
michael@0 88 lo = mid + 1;
michael@0 89 }
michael@0 90 }
michael@0 91
michael@0 92 if (lo == rangeCount) {
michael@0 93 mCurrentRangeIndex = rangeCount - 1;
michael@0 94 } else if (aOffset < ranges[lo].SkippedOffset()) {
michael@0 95 mCurrentRangeIndex = lo - 1;
michael@0 96 if (mCurrentRangeIndex == -1) {
michael@0 97 mOriginalStringOffset = aOffset;
michael@0 98 return;
michael@0 99 }
michael@0 100 } else {
michael@0 101 mCurrentRangeIndex = lo;
michael@0 102 }
michael@0 103
michael@0 104 const gfxSkipChars::SkippedRange& r = ranges[mCurrentRangeIndex];
michael@0 105 mOriginalStringOffset = r.End() + aOffset - r.SkippedOffset();
michael@0 106 }
michael@0 107
michael@0 108 bool
michael@0 109 gfxSkipCharsIterator::IsOriginalCharSkipped(int32_t* aRunLength) const
michael@0 110 {
michael@0 111 if (mCurrentRangeIndex == -1) {
michael@0 112 // we're before the first skipped range (if any)
michael@0 113 if (aRunLength) {
michael@0 114 uint32_t end = mSkipChars->mRanges.IsEmpty() ?
michael@0 115 mSkipChars->mCharCount : mSkipChars->mRanges[0].Start();
michael@0 116 *aRunLength = end - mOriginalStringOffset;
michael@0 117 }
michael@0 118 return mSkipChars->mCharCount == uint32_t(mOriginalStringOffset);
michael@0 119 }
michael@0 120
michael@0 121 const gfxSkipChars::SkippedRange& range =
michael@0 122 mSkipChars->mRanges[mCurrentRangeIndex];
michael@0 123
michael@0 124 if (uint32_t(mOriginalStringOffset) < range.End()) {
michael@0 125 if (aRunLength) {
michael@0 126 *aRunLength = range.End() - mOriginalStringOffset;
michael@0 127 }
michael@0 128 return true;
michael@0 129 }
michael@0 130
michael@0 131 if (aRunLength) {
michael@0 132 uint32_t end =
michael@0 133 uint32_t(mCurrentRangeIndex) + 1 < mSkipChars->mRanges.Length() ?
michael@0 134 mSkipChars->mRanges[mCurrentRangeIndex + 1].Start() :
michael@0 135 mSkipChars->mCharCount;
michael@0 136 *aRunLength = end - mOriginalStringOffset;
michael@0 137 }
michael@0 138
michael@0 139 return mSkipChars->mCharCount == uint32_t(mOriginalStringOffset);
michael@0 140 }

mercurial