Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Appends a run of text with the given TsTextProps.
        /// </summary>
        /// <param name="sRun">The text to append</param>
        /// <param name="props">The properties to use</param>
        /// ------------------------------------------------------------------------------------
        public void AppendRun(string sRun, ITsTextProps props)
        {
            CheckDisposed();
            //note: For efficiency, we usually skip the Replace() if the string is empty.
            // However, if the builder is has Length == 0, then we want to replace the
            // properties on the empty run of the TsString.
            // A TsString always has at least one run, even if it is empty, and this controls
            // the props when the user begins to enter text in an empty para.
            if (sRun != string.Empty || Length == 0)
            {
                System.Diagnostics.Debug.Assert(props != null);
                int var;
                int ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out var);

                // Make sure we handle the magic writing systems
                if (ws == (int)CellarModuleDefns.kwsAnal)
                {
                    // default analysis writing system
                    ITsPropsBldr bldr = props.GetBldr();
                    bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
                                          m_cache.DefaultAnalWs);
                    props = bldr.GetTextProps();
                }
                else if (ws == (int)CellarModuleDefns.kwsVern)
                {
                    // default vernacular writing system
                    ITsPropsBldr bldr = props.GetBldr();
                    bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
                                          m_cache.DefaultVernWs);
                    props = bldr.GetTextProps();
                }
                else
                {
                    System.Diagnostics.Debug.Assert(ws > 0);                            // not quite right if >2G objects.
                }
                m_ParaStrBldr.Replace(Length, Length, sRun, props);
            }
        }
Esempio n. 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add the given text and props as a new run to the end of the specified paragraph
		/// under construction.
		/// </summary>
		/// <param name="sText">Text to be appended to the paragraph being built</param>
		/// <param name="pttpProps">Properties (should contain only a named style) for the run
		/// of text to be added.</param>
		/// <param name="strbldr">String builder of paragraph being built</param>
		/// ------------------------------------------------------------------------------------
		protected void AddTextToPara(string sText, ITsTextProps pttpProps, ITsStrBldr strbldr)
		{
			// Don't bother trying to add empty runs. Also don't add runs consisting of a single
			// space if processing a marker that maps to a paragraph style.
			if (sText.Length > 0 &&
				(sText != " " || m_styleProxy.StyleType == StyleType.kstCharacter))
			{
				// send the text and props directly to the Builder, after first ensuring that
				// a ws is specified.
				int var;
				int ws = pttpProps.GetIntPropValues((int)FwTextPropType.ktptWs,
					out var);
				if (ws == -1)
				{
					ws = GetWsForContext(strbldr);
					ITsPropsBldr tpb = pttpProps.GetBldr();
					tpb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
					pttpProps = tpb.GetTextProps();
				}
				int cchLength = strbldr.Length;
				// Remove extra space.
				if (cchLength > 0 && UnicodeCharProps.get_IsSeparator(sText[0]))
				{
					string s = strbldr.GetChars(cchLength - 1, cchLength);
					if (UnicodeCharProps.get_IsSeparator(s[0]))
						sText = sText.Substring(1);
				}

				if (sText != string.Empty || cchLength == 0)
					strbldr.Replace(cchLength, cchLength, sText, pttpProps);
			}
		}
Esempio n. 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Appends a run of text with the given TsTextProps.
		/// </summary>
		/// <param name="sRun">The text to append</param>
		/// <param name="props">The properties to use</param>
		/// ------------------------------------------------------------------------------------
		public void AppendRun(string sRun, ITsTextProps props)
		{
			CheckDisposed();
			//note: For efficiency, we usually skip the Replace() if the string is empty.
			// However, if the builder is has Length == 0, then we want to replace the
			// properties on the empty run of the TsString.
			// A TsString always has at least one run, even if it is empty, and this controls
			// the props when the user begins to enter text in an empty para.
			if (sRun != string.Empty || Length == 0)
			{
				System.Diagnostics.Debug.Assert(props != null);
				int var;
				int ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out var);

				// Make sure we handle the magic writing systems
				if (ws == (int)CellarModuleDefns.kwsAnal)
				{
					// default analysis writing system
					ITsPropsBldr bldr = props.GetBldr();
					bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
						m_cache.DefaultAnalWs);
					props = bldr.GetTextProps();
				}
				else if (ws == (int)CellarModuleDefns.kwsVern)
				{
					// default vernacular writing system
					ITsPropsBldr bldr = props.GetBldr();
					bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
						m_cache.DefaultVernWs);
					props = bldr.GetTextProps();
				}
				else
				{
					System.Diagnostics.Debug.Assert(ws > 0);	// not quite right if >2G objects.
				}
				m_ParaStrBldr.Replace(Length, Length, sRun, props);
			}
		}
Esempio n. 4
0
		public override ITsTextProps UpdateRootBoxTextProps(ITsTextProps ttp)
		{
			ITsPropsBldr propsBldr = ttp.GetBldr();
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault,
				(int)RGB(m_innerTextBox.BackColor));

			using (Graphics graphics = m_innerTextBox.CreateGraphics())
			{
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptPadTop, (int)FwTextPropVar.ktpvMilliPoint,
					m_innerTextBox.Padding.Top * 72000 / (int)graphics.DpiY);
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptPadBottom, (int)FwTextPropVar.ktpvMilliPoint,
					m_innerTextBox.Padding.Bottom * 72000 / (int)graphics.DpiY);
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint,
					(m_rtl ? m_innerTextBox.Padding.Right : m_innerTextBox.Padding.Left) * 72000 / (int)graphics.DpiX);
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint,
					(m_rtl ? m_innerTextBox.Padding.Left : m_innerTextBox.Padding.Right) * 72000 / (int)graphics.DpiX);
			}

			return propsBldr.GetTextProps();
		}
Esempio n. 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// In a string builder, updates the given ORC (Object Replacement Character) run
		/// with new object data.
		/// </summary>
		/// <param name="bldr">tss builder holding the ORC run</param>
		/// <param name="ttp">text properties of the ORC run</param>
		/// <param name="tri">The info for the ORC run, including min/lim character indices.</param>
		/// <param name="odt">object data type indicating to which type of object ORC points</param>
		/// <param name="guidOfNewObj">The GUID of new object, to update the ORC</param>
		/// ------------------------------------------------------------------------------------
		private static void UpdateORCforNewObjData(ITsStrBldr bldr, ITsTextProps ttp,
			TsRunInfo tri, FwObjDataTypes odt, Guid guidOfNewObj)
		{
			// build new ObjData properties of the ORC for the new object
			byte[] objData = MiscUtils.GetObjData(guidOfNewObj, (byte)odt);
			ITsPropsBldr propsBldr = ttp.GetBldr();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
				objData, objData.Length);

			// update the run props in the string builder
			bldr.SetProperties(tri.ichMin, tri.ichLim, propsBldr.GetTextProps());
		}
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Replaces the string.
        /// </summary>
        /// <param name="tsbBuilder">The string builder for the text to be replaced.</param>
        /// <param name="tssInput">The input string to be replaced.</param>
        /// <param name="ichMinInput">The start in the input string.</param>
        /// <param name="ichLimInput">The lim in the input string.</param>
        /// <param name="tssReplace">The replacement text. This should come from VwPattern.ReplacementText,
        /// NOT VwPattern.ReplaceWith. The former includes any ORCs that need to be saved from the input, as well as
        /// properly handling $1, $2 etc. in regular expressions.</param>
        /// <param name="delta">length difference between tssInput and tsbBuilder from previous
        /// replacements.</param>
        /// <param name="fEmptySearch"><c>true</c> if search text is empty (irun.e. we're searching
        /// for a style or Writing System)</param>
        /// <param name="fUseWs">if set to <c>true</c> use the writing system used in the
        /// replace string of the Find/Replace dialog.</param>
        /// <returns>Change in length of the string.</returns>
        /// ------------------------------------------------------------------------------------
        public static int ReplaceString(ITsStrBldr tsbBuilder, ITsString tssInput,
                                        int ichMinInput, int ichLimInput, ITsString tssReplace, int delta, bool fEmptySearch,
                                        bool fUseWs)
        {
            int initialLength   = tsbBuilder.Length;
            int replaceRunCount = tssReplace.RunCount;

            // Determine whether to replace the sStyleName. We do this if any of the runs of
            // the replacement string have the sStyleName set (to something other than
            // Default Paragraph Characters).
            bool fUseStyle = false;
            bool fUseTags  = false;

            // ENHANCE (EberhardB): If we're not doing a RegEx search we could store these flags
            // since they don't change.
            TsRunInfo runInfo;

            for (int irunReplace = 0; irunReplace < replaceRunCount; irunReplace++)
            {
                ITsTextProps textProps  = tssReplace.FetchRunInfo(irunReplace, out runInfo);
                string       sStyleName =
                    textProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
                if (sStyleName != null && sStyleName.Length > 0)
                {
                    fUseStyle = true;
                }

                //string tags = textProps.GetStrPropValue((int)FwTextPropType.ktptTags);
                //if (tags.Length > 0)
                //    fUseTags = true;
            }

            int          iRunInput = tssInput.get_RunAt(ichMinInput);
            ITsTextProps selProps  = tssInput.get_Properties(iRunInput);
            ITsPropsBldr propsBldr = selProps.GetBldr();

            // Remove all tags that are anywhere in the Find-what string. But also include any
            // other tags that are present in the first run of the found string. So the resulting
            // replacement string will have any tags in the first char of the selection plus
            // any specified replacement tags.
            //			Vector<StrUni> vstuTagsToRemove;
            //			GetTagsToRemove(m_qtssFindWhat, &fUseTags, vstuTagsToRemove);
            //			Vector<StrUni> vstuTagsToInclude;
            //			GetTagsToInclude(qtssSel, vstuTagsToRemove, vstuTagsToInclude);

            // Make a string builder to accumulate the real replacement string.

            // Copy the runs of the replacement string, adjusting the properties.
            // Make a string builder to accumulate the real replacement string.
            ITsStrBldr stringBldr = TsStrBldrClass.Create();

            // Copy the runs of the replacement string, adjusting the properties.
            for (int irun = 0; irun < replaceRunCount; irun++)
            {
                ITsTextProps ttpReplaceRun = tssReplace.FetchRunInfo(irun, out runInfo);
                if (TsStringUtils.GetGuidFromRun(tssReplace, irun) != Guid.Empty)
                {
                    // If the run was a footnote or picture ORC, then just use the run
                    // properties as they are.
                }
                else if (fUseWs || fUseStyle || fUseTags)
                {
                    // Copy only writing system/old writing system, char sStyleName and/or
                    // tag info into the builder.
                    if (fUseWs)
                    {
                        int ttv, ws;
                        ws = ttpReplaceRun.GetIntPropValues((int)FwTextPropType.ktptWs, out ttv);
                        propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, ttv, ws);
                    }
                    if (fUseStyle)
                    {
                        string sStyleName = ttpReplaceRun.GetStrPropValue(
                            (int)FwTextPropType.ktptNamedStyle);

                        if (sStyleName == FwStyleSheet.kstrDefaultCharStyle)
                        {
                            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                                      null);
                        }
                        else
                        {
                            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                                      sStyleName);
                        }
                    }
                    //if (fUseTags)
                    //{
                    //    string sTagsRepl = ttpReplaceRun.GetStrPropValue(ktptTags);
                    //    string sTags = AddReplacementTags(vstuTagsToInclude, sTagsRepl);
                    //    propsBldr.SetStrPropValue(ktptTags, sTags);
                    //}
                    ttpReplaceRun = propsBldr.GetTextProps();
                }
                else
                {
                    // Its not a footnote so copy all props exactly from (the first run of the) matched text.
                    ttpReplaceRun = selProps;
                }

                // Insert modified run into string builder.
                if (fEmptySearch && tssReplace.Length == 0)
                {
                    // We are just replacing an ws/ows/sStyleName/tags. The text remains unchanged.
                    // ENHANCE (SharonC): Rework this when we get patterns properly implemented.
                    string runText = tssInput.get_RunText(iRunInput);
                    if (runText.Length > ichLimInput - ichMinInput)
                    {
                        runText = runText.Substring(0, ichLimInput - ichMinInput);
                    }
                    stringBldr.Replace(0, 0, runText, ttpReplaceRun);
                }
                else
                {
                    stringBldr.Replace(runInfo.ichMin, runInfo.ichMin,
                                       tssReplace.get_RunText(irun), ttpReplaceRun);
                }
            }

            tsbBuilder.ReplaceTsString(delta + ichMinInput, delta + ichLimInput, stringBldr.GetString());
            int finalLength = tsbBuilder.Length;

            return(finalLength - initialLength);
        }