Exemple #1
0
        public void UnicodePropTest()
        {
            // Set class first, or it will throw an exception.
            const int hvo      = 1;
            var       clidAnal = SilDataAccess.MetaDataCache.GetClassId("ClassE");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clidAnal);

            // Set its 'UnicodeProp4' property, using the 'BSTR' method.
            var          tag = SilDataAccess.MetaDataCache.GetFieldId("ClassE", "UnicodeProp4", false);
            const string ec  = "ZPI";

            SilDataAccess.set_UnicodeProp(hvo, tag, ec);
            var ec2 = SilDataAccess.get_UnicodeProp(hvo, tag);

            Assert.AreEqual(ec, ec2, "Wrong Unicode string in cache.");

            // Set its 'UnicodeProp4' property, using non-bstr method.
            const string ecNew = "ZPR";

            SilDataAccess.SetUnicode(hvo, tag, ecNew, ecNew.Length);
            int len;

            SilDataAccess.UnicodePropRgch(hvo, tag, null, 0, out len);
            Assert.AreEqual(ecNew.Length, len);
            using (var arrayPtr = MarshalEx.StringToNative(len + 1, true))
            {
                int cch;
                SilDataAccess.UnicodePropRgch(hvo, tag, arrayPtr, len + 1, out cch);
                var ecNew2 = MarshalEx.NativeToString(arrayPtr, cch, true);
                Assert.AreEqual(ecNew, ecNew2);
                Assert.AreEqual(ecNew2.Length, cch);
                Assert.IsTrue(SilDataAccess.IsDirty());
            }
        }
Exemple #2
0
 /// <summary>
 /// Get the specified range of (rendered) characters from the text source.
 /// </summary>
 string Fetch(int ichMin, int ichLim)
 {
     using (ArrayPtr ptr = new ArrayPtr(ichLim - ichMin))
     {
         m_para.Source.Fetch(ichMin, ichLim, ptr.IntPtr);
         return(MarshalEx.NativeToString(ptr, ichLim - ichMin, true));
     }
 }
        // Verify that source.Fetch(min, lim) produces the specified string
        private void VerifyFetch(TextSource source, int min, int lim, string expected)
        {
            string got;

            using (ArrayPtr ptr = new ArrayPtr((lim - min) * 2 + 2))
            {
                source.Fetch(min, lim, ptr.IntPtr);
                got = MarshalEx.NativeToString(ptr, lim - min, true);
            }
            Assert.AreEqual(expected, got, "fetch from " + min + " to " + lim);
        }
Exemple #4
0
        public void FetchChars_TwoRuns_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(11, true))
            {
                tss.FetchChars(25, 36, rgch);
                string str = MarshalEx.NativeToString(rgch, 11, true);
                Assert.That(str, Is.EqualTo("una prueba!"));
            }
        }
Exemple #5
0
        public void FetchChars_OneRun_ReturnsCorrectString()
        {
            TsString tss = CreateOneRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(6, true))
            {
                tss.FetchChars(1, 7, rgch);
                string str = MarshalEx.NativeToString(rgch, 6, true);
                Assert.That(str, Is.EqualTo("his is"));
            }
        }
Exemple #6
0
        public void FetchChars_Empty_ReturnsEmptyString()
        {
            TsString tss = CreateEmptyString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(0, true))
            {
                tss.FetchChars(0, 0, rgch);
                string str = MarshalEx.NativeToString(rgch, 0, true);
                Assert.That(str, Is.EqualTo(string.Empty));
            }
        }
Exemple #7
0
        public void UnicodeProp()
        {
            CheckDisposed();
            string strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);

            Assert.IsNull(strNew);
            Assert.IsFalse(m_ISilDataAccess.IsDirty());

            string str = "UnicodeTest";

            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "SecondUnicodeTest";
            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "ThirdUnicodeTest";
            m_ISilDataAccess.set_UnicodeProp(1119, 2229, str);
            int cch;

            using (ArrayPtr arrayPtr = MarshalEx.StringToNative(100, true))
            {
                m_ISilDataAccess.UnicodePropRgch(1119, 2229, arrayPtr, 100, out cch);
                strNew = MarshalEx.NativeToString(arrayPtr, cch, true);
                Assert.AreEqual(str, strNew);
                Assert.AreEqual(str.Length, cch);
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                m_ISilDataAccess.UnicodePropRgch(1119, 2229, ArrayPtr.Null, 0, out cch);
                Assert.AreEqual(str.Length, cch);

                CheckProp(1119, 2229, str, CellarModuleDefns.kcptUnicode);
            }
        }
Exemple #8
0
        /// <summary>
        /// Emulate what a real renderer will do, assuming character widths are as determined by CharWidth,
        /// and only space is a valid line break.
        /// Including width of white space:
        /// Basically, if the white space is known to end the line, we don't count its width.
        /// - If we stopped mid-line because of a hard break, ichLim{backtracking} != source length, etc.,
        /// we will try to put more on line, so must include space width.
        /// - If we stop at the very end of the whole paragraph, don't include it? But then how can IP be after
        /// final space?
        /// - If we know next stuff must go on another line leave out its width.
        /// </summary>
        public void FindBreakPoint(IVwGraphics vg, IVwTextSource source, IVwJustifier justifier,
                                   int ichMin, int ichLim, int ichLimBacktrack, bool fNeedFinalBreak, bool fStartLine, int dxMaxWidth,
                                   LgLineBreak lbPref, LgLineBreak lbMax, LgTrailingWsHandling twsh, bool fParaRightToLeft,
                                   out ILgSegment segRet, out int dichLimSeg, out int dxWidth, out LgEndSegmentType est, ILgSegment segPrev)
        {
            // Default return values in case we cannot make a segment.
            segRet     = null;
            dichLimSeg = 0;
            dxWidth    = 0;
            est        = LgEndSegmentType.kestNothingFit;

            int    width     = 0;
            int    lastSpace = -1;
            string input;
            int    cchRead = ichLim - ichMin;

            if (fNeedFinalBreak)
            {
                cchRead++;
            }
            using (ArrayPtr ptr = new ArrayPtr((cchRead) * 2 + 2))
            {
                source.Fetch(ichMin, ichMin + cchRead, ptr.IntPtr);
                input = MarshalEx.NativeToString(ptr, cchRead, true);
            }
            int widthAtLastSpace = 0;

            int ichLimWs = GetLimInSameWs(ichMin, source, ichLimBacktrack);

            FakeSegment result = null;
            // limit in input of characters we may include in segment.
            int limit         = Math.Min(ichLimBacktrack, ichLimWs) - ichMin;
            int limWholeInput = ichLim - ichMin;
            int ichInput      = 0;

            if (twsh == LgTrailingWsHandling.ktwshOnlyWs)
            {
                result = MakeWhiteSpaceOnlySegment(input, width, ichInput, limit);
            }
            else             // mixed allowed or no-white-space
            {
                // Advance past what will fit, keeping track of the last good break position (white space).
                for (; ichInput < limit; ichInput++)
                {
                    if (input[ichInput] == ' ')
                    {
                        lastSpace        = ichInput;
                        widthAtLastSpace = width;
                    }
                    var charWidth = CharWidth(input[ichInput]);
                    if (width + charWidth > dxMaxWidth)
                    {
                        break;
                    }
                    width += charWidth;
                }
                Debug.Assert(width <= dxMaxWidth);                 // loop never allows it to exceed max
                if (ichInput < input.Length && input[ichInput] == ' ')
                {
                    // good break exactly at limit
                    lastSpace        = ichInput;
                    widthAtLastSpace = width;
                }

                if (ichInput == limit && ichLimBacktrack >= ichLimWs)                 // all the text in our WS fit; also handles special case of zero-char range
                {
                    // everything we were allowed to include fit; if it wasn't absolutely everything caller needs to decide
                    // about break.
                    if (twsh == LgTrailingWsHandling.ktwshAll)
                    {
                        result = new FakeSegment(input.Substring(0, limit), width, Ws,
                                                 ichInput == limWholeInput ? LgEndSegmentType.kestNoMore : LgEndSegmentType.kestWsBreak);
                    }
                    else
                    {
                        // must be no-trailing-white-space (all WS is handled above). strip off any trailing spaces.
                        while (ichInput > 0 && input[ichInput - 1] == ' ')
                        {
                            ichInput--;
                            width -= CharWidth(' ');
                        }
                        if (ichInput == limit)                         // no trailing ws removed (also handles empty run)
                        {
                            result = new FakeSegment(input.Substring(0, limit), width, Ws,
                                                     ichInput == limWholeInput ? LgEndSegmentType.kestNoMore : LgEndSegmentType.kestWsBreak); // all fit
                        }
                        else if (ichInput > 0)                                                                                                // got some text, stripped some white space
                        {
                            result = new FakeSegment(input.Substring(0, ichInput), width, Ws, LgEndSegmentType.kestMoreWhtsp);
                        }
                        else
                        {
                            // we're not done with the whole input, but no non-white at start
                            return;
                        }
                    }
                }
                else                 // some stuff we wanted to put on line didn't fit;
                if (lastSpace >= 0)  // there's a good break we can use
                {
                    int end = lastSpace;
                    if (twsh == LgTrailingWsHandling.ktwshAll)
                    {
                        // include trailing spaces without increasing width; they 'disappear' into line break.
                        while (end < limit && input[end] == ' ')
                        {
                            end++;
                        }
                    }
                    result = new FakeSegment(input.Substring(0, end), widthAtLastSpace, Ws,
                                             LgEndSegmentType.kestMoreLines);
                }
                else if (lbMax == LgLineBreak.klbWordBreak)
                {
                    // we needed a word break and didn't get one.
                    return;
                }
                else
                {
                    // remaining possibility is that we need to make some sort of segment with at least one character.
                    // (if we don't have any i = limit = 0 and we take another branch).
                    if (ichInput == 0)
                    {
                        width += CharWidth(input[ichInput]);
                        ichInput++;                                 // must have at least one character
                    }
                    result = new FakeSegment(input.Substring(ichInput), width, Ws, LgEndSegmentType.kestMoreLines);
                }
            }
            if (result == null)
            {
                return;
            }
            segRet        = result;
            dichLimSeg    = result.Length;
            dxWidth       = result.Width;
            est           = result.EndSegType;
            result.Height = SegmentHeight;
            result.Ascent = SegmentAscent;
            // DirectionDepth is usually 0 for LTR text in an LTR paragraph.
            // For RTL text, however, it is always 1.
            // And for UPSTREAM LTR text (in an RTL paragraph) it has to be 2.
            if (RightToLeft)
            {
                result.DirectionDepth = 1;
            }
            else if (fParaRightToLeft)
            {
                result.DirectionDepth = 2;
            }
        }