/// <summary> /// Initializes the trimming class /// </summary> /// <param name="fdmexec">a JSBSim executive object</param> /// <param name="tm">trim mode</param> public Trim(FDMExecutive exec, TrimMode tm) { N = Nsub = 0; max_iterations = 60; max_sub_iterations = 100; Tolerance = 1E-3; A_Tolerance = Tolerance / 10; Debug = 0; DebugLevel = 0; fdmex = exec; fgic = fdmex.GetIC(); total_its = 0; trimudot = true; gamma_fallback = true; axis_count = 0; mode = tm; xlo = xhi = alo = ahi = 0.0; targetNlf = 1.0; debug_axis = StateType.All; SetMode(tm); if (log.IsDebugEnabled) { log.Debug("Instantiated: FGTrim"); } }
internal void SaveToXml(XmlHelper writer) { writer.mWriter.WriteStartElement("Field"); writer.mWriter.WriteStartAttribute("Name", ""); writer.mWriter.WriteString(mFieldName); writer.mWriter.WriteEndAttribute(); writer.mWriter.WriteStartAttribute("Type", ""); writer.mWriter.WriteString(mFieldType); writer.mWriter.WriteEndAttribute(); WriteHeaderAttributes(writer); Converter.WriteXml(writer); writer.WriteElement("Visibility", Visibility.ToString(), "Public"); writer.WriteElement("FieldIgnored", FieldIgnored); writer.WriteElement("FieldOptional", FieldOptional); writer.WriteElement("FieldInNewLine", FieldInNewLine); writer.WriteElement("TrimChars", TrimChars, " \t"); writer.WriteElement("TrimMode", TrimMode.ToString(), "None"); if (FieldNullValue != null) { writer.mWriter.WriteStartElement("FieldNullValue"); writer.mWriter.WriteStartAttribute("Type", ""); writer.mWriter.WriteString(mFieldNullValue.GetType().FullName); writer.mWriter.WriteEndAttribute(); writer.mWriter.WriteString(mFieldNullValue.ToString()); writer.mWriter.WriteEndElement(); } WriteExtraElements(writer); writer.mWriter.WriteEndElement(); }
private string TrimEnclosed(TrimMode mode, string val) { if (val == null || val == "") { return(""); } switch (_trimMode) { case TrimMode.TrimStart: val = val.TrimStart(); break; case TrimMode.TrimEnd: val = val.TrimEnd(); break; case TrimMode.Both: val = val.Trim(); break; } var len = val.Length; if (_enclosed != '\0' && len >= 2 && val[0] == _enclosed && val[len - 1] == _enclosed) { val = val.Substring(1, len - 2); } return(val); }
static void TestLoadAndReload(string filename) { //Trimmable feature tests: //[A] read the font file as usual => get full information about the font Typeface typeface = null; using (FileStream fs = new FileStream(filename, FileMode.Open)) { //read in full mode OpenFontReader openFontReader = new OpenFontReader(); typeface = openFontReader.Read(fs); } //before bool hasColor1 = typeface.HasColorTable(); bool hasSvg1 = typeface.HasSvgTable(); bool hasCff1 = typeface.IsCffFont; TrimMode glyphMode1 = typeface.GetTrimMode(); Glyph g1_1 = typeface.GetGlyph(1); //--------------------------------------------------------- //[B] if you create paths from glyphs, or atlas from glyph // and you don't want any glyph-building-detail (eg. to reduce memory usuage) // but you still want to use the typeface for text-layout // you can trim it down RestoreTicket ticket = typeface.TrimDown();//*** //[C] you can GetGlyph() but this is ANOTHER NEW GLYPH //without building instruction( eg. no cff,ttf,svg data,bitmap) Glyph g1_2 = typeface.GetGlyph(1); //** if you cache the the old version of 'full-info' glyph** // the info is still cache on the old glyph and it can be used as 'full-info' glyph // TrimDown() DOES NOT go to delete that glyph. bool hasColor2 = typeface.HasColorTable(); bool hasSvg2 = typeface.HasSvgTable(); bool hasCff2 = typeface.IsCffFont; TrimMode glyphMode2 = typeface.GetTrimMode(); //--------------------------------------------------------- //[D] can we load glyph detail again? //yes=> this need 'ticket' from latest TrimDown() //if you don't have it, you can't restore it. using (FileStream fs = new FileStream(filename, FileMode.Open)) { typeface.RestoreUp(ticket, fs); } }
/// <summary> /// удалить вхождения строки в начале и в конце исходной строки /// </summary> /// <param name="sourceString">исходная строка</param> /// <param name="stringToTrim">удаляемая строка</param> /// <param name="mode"></param> /// <returns>строка с отсутствием заданной строки в начале и в конце</returns> public static string Trim(this string sourceString, string stringToTrim, TrimMode mode = TrimMode.None) { int charactersToTrim = GetCharactersToTrimStart(sourceString, stringToTrim, mode); int charactersToLeave = GetCharactersToLeaveToTrimEnd(sourceString, stringToTrim, mode); charactersToLeave -= charactersToTrim; if (charactersToLeave < 0) { charactersToLeave = 0; } return(sourceString.Substring(charactersToTrim, charactersToLeave)); }
/// <summary> /// Reads an indented block from the underlying string. An indented block consists of several lines where each line starts with some white space. The number of whitespace characters is at least <paramref name="indentLevel"/>. /// </summary> /// <param name="indentLevel">The indent level indicating the number of spaces ahead of the text in each line of this indented block.</param> /// <param name="trimStart"><see cref="TrimMode.NoTrim"/> if the white spaces at the start of every line of the block should be be trimmed; <see cref="TrimMode.KeepIndent"/> if a number of whitespaces is preserved while others are trimmed where the number is <paramref name="indentLevel"/>; <see cref="TrimMode.TrimAll"/> if all white spaces are trimmed.</param> /// <param name="trimEnd"><c>true</c> if all white spaces at the end of every line of the block are trimmed.</param> /// <returns></returns> public string ReadIndentedBlock(int indentLevel = 1, TrimMode trimStart = TrimMode.NoTrim, bool trimEnd = false) { var sb = new StringBuilder(); if (indentLevel == 1) { while (First.NotIn(Environment.NewLine) && First.IsWhiteSpace()) { if (trimStart != TrimMode.TrimAll) { sb.Append(Read()); } var option = ReadOptions.StopAfterKey; if (trimStart != TrimMode.NoTrim) { option |= ReadOptions.TrimStart; } if (trimEnd) { option |= ReadOptions.TrimEnd; } sb.Append(ReadLine(option)); } } else { while (ReadWhiteSpace(indentLevel, out string whitespace)) { if (trimStart != TrimMode.TrimAll) { sb.Append(whitespace); } var option = ReadOptions.StopAfterKey; if (trimStart != TrimMode.NoTrim) { option |= ReadOptions.TrimStart; } if (trimEnd) { option |= ReadOptions.TrimEnd; } sb.Append(ReadLine(option)); } } return(sb.ToString()); }
/// <summary> /// 构造函数 /// </summary> /// <param name="fileName">文件名</param> /// <param name="encoding">编码,null表示自动获取编码(不一定准确)</param> /// <param name="fieldTermiter">字段分割符号</param> /// <param name="enclosed">字段封闭符号,'\0'表示无封闭符号</param> /// <param name="schemaTable">字段名称、类型、表名在这里设置</param> /// <param name="fieldsNums">要操作的字段index,如{0,1,2,3,4,},数量和schemaTable的Colunms数量一至,如果index超出,值设置为"",此参数可为null</param> /// <param name="trimMode"></param> public TextDataReader(string fileName, System.Text.Encoding encoding, char fieldTermiter, char enclosed, DataTable schemaTable, int[] fieldsNums, TrimMode trimMode) { _fileName = fileName; _trimMode = trimMode; _schemaTable = schemaTable; _fieldTermiter = fieldTermiter; _enclosed = enclosed; for (int i = 0; i < _schemaTable.Columns.Count; i++) { _colNames.Add(_schemaTable.Columns[i].ColumnName, i); } var count = FieldCount; if (fieldsNums != null) { _fieldsNums = fieldsNums; } else { _fieldsNums = new int[count]; for (int i = 0; i < count; i++) { _fieldsNums[i] = i; } } if (_fieldsNums.Length != count) { throw new Exception("要操作的字段与schemaTable字段数目不一致!"); } if (encoding == null) { encoding = Extensions.MyFunction.GetEncoding(fileName); } _encoding = encoding; _fileReader = new StreamReader(fileName, encoding); _isOpened = true; }
private String TrimString(string extractedString) { switch (TrimMode) { case TrimMode.None: return(extractedString); case TrimMode.Both: return(extractedString.Trim()); case TrimMode.Left: return(extractedString.TrimStart()); case TrimMode.Right: return(extractedString.TrimEnd()); default: throw new Exception("Trim mode invalid in FieldBase.TrimString -> " + TrimMode.ToString()); } }
private static unsafe int GetCharactersToLeaveToTrimEnd(string sourceString, string stringToTrim, TrimMode mode) { int stringToTrimLength = stringToTrim.Length; int sourceStringLength = sourceString.Length; int charactersToLeave = sourceString.Length; int charToTrimIndex = stringToTrimLength - 1; fixed(char *charToTrim = stringToTrim) fixed(char *sourceChar = sourceString) while (charactersToLeave > 0) { if (sourceChar[charactersToLeave - 1] != charToTrim[charToTrimIndex--]) { break; } charactersToLeave--; if ((mode & TrimMode.Once) != TrimMode.None && sourceStringLength - charactersToLeave == stringToTrimLength) { break; } if (charToTrimIndex < 0) { charToTrimIndex = stringToTrimLength - 1; } } if ((mode & TrimMode.WholeEntry) != TrimMode.None) { charactersToLeave += (sourceStringLength - charactersToLeave) % stringToTrimLength; } return(charactersToLeave); }
private static unsafe int GetCharactersToTrimStart(string sourceString, string stringToTrim, TrimMode mode) { int stringToTrimLength = stringToTrim.Length; int sourceStringLength = sourceString.Length; int charToTrimIndex = 0; int charactersToTrim = 0; fixed(char *charToTrim = stringToTrim) fixed(char *sourceChar = sourceString) while (charactersToTrim < sourceStringLength - 1) { if (sourceChar[charactersToTrim] != charToTrim[charToTrimIndex]) { break; } charactersToTrim++; if ((mode & TrimMode.Once) != TrimMode.None && charactersToTrim == stringToTrimLength) { break; } charToTrimIndex = (charToTrimIndex + 1) % sourceStringLength; } if ((mode & TrimMode.WholeEntry) != TrimMode.None) { charactersToTrim -= charactersToTrim % stringToTrimLength; } return(charactersToTrim); }
public void DoTrim(TrimMode mode) { DoTrim((int)mode); }
public FieldInfoBuilder SetTrimMode(TrimMode trimMode) { TrimMode = trimMode; return(this); }
private void SetPragma(string pragma) { if (string.IsNullOrEmpty(pragma)) return; switch (pragma) { case "trim": { TrimMode = TrimMode.Greedy; break; } case "notrim": { TrimMode = TrimMode.FollowingNewLine; break; } } }
/// <summary> /// Clear all state-control pairs and set a predefined trim mode /// </summary> /// <param name="tm">the set of axes to trim. Can be: /// tLongitudinal, tFull, tGround, tCustom, or tNone</param> public void SetMode(TrimMode tm) { ClearStates(); mode = tm; switch (tm) { case TrimMode.Full: if (log.IsDebugEnabled) { log.Debug(" Full Trim"); } TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Wdot, ControlType.Alpha)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Udot, ControlType.Throttle)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Qdot, ControlType.PitchTrim)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Hmgt, ControlType.Beta)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Vdot, ControlType.Phi)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Pdot, ControlType.Aileron)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Rdot, ControlType.Rudder)); break; case TrimMode.Longitudinal: if (log.IsDebugEnabled) { log.Debug(" Longitudinal Trim"); } TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Wdot, ControlType.Alpha)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Udot, ControlType.Throttle)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Qdot, ControlType.PitchTrim)); break; case TrimMode.Ground: if (log.IsDebugEnabled) { log.Debug(" Ground Trim"); } TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Wdot, ControlType.AltAGL)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Qdot, ControlType.Theta)); //TrimAxes.push_back(new TrimAxis(fdmex,fgic,tPdot,tPhi )); break; case TrimMode.Pullup: TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Nlf, ControlType.Alpha)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Udot, ControlType.Throttle)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Qdot, ControlType.PitchTrim)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Hmgt, ControlType.Beta)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Vdot, ControlType.Phi)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Pdot, ControlType.Aileron)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Rdot, ControlType.Rudder)); break; case TrimMode.Turn: TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Wdot, ControlType.Alpha)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Udot, ControlType.Throttle)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Qdot, ControlType.PitchTrim)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Vdot, ControlType.Beta)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Pdot, ControlType.Aileron)); TrimAxes.Add(new TrimAxis(fdmex, fgic, StateType.Rdot, ControlType.Rudder)); break; case TrimMode.Custom: case TrimMode.None: break; } //cout + "TrimAxes.size(): " + TrimAxes.size() + endl; sub_iterations = new double[TrimAxes.Count]; successful = new double[TrimAxes.Count]; solution = new bool[TrimAxes.Count]; current_axis = 0; }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. </summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> /// <param name="chars">A list of chars used to trim.</param> public FieldTrimAttribute(TrimMode mode, params char[] chars) { TrimMode = mode; Array.Sort(chars); TrimChars = chars; }
/// <summary> /// удалить вхождения строки в конце исходной строки /// </summary> /// <param name="sourceString">исходная строка</param> /// <param name="stringToTrim">удаляемая строка</param> /// <param name="mode"></param> /// <returns>строка с отсутствием заданной строки в конце</returns> public static string TrimEnd(this string sourceString, string stringToTrim, TrimMode mode = TrimMode.None) { int charactersToLeave = GetCharactersToLeaveToTrimEnd(sourceString, stringToTrim, mode); return(sourceString.Substring(0, charactersToLeave)); }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. </summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> /// <param name="trimChars">A string of chars used to trim.</param> public FieldTrimAttribute(TrimMode mode, string trimChars) : this(mode, trimChars.ToCharArray()) { }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. By default trims the blank spaces and tabs.</summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> public FieldTrimAttribute(TrimMode mode) : this(mode, LineInfo.WhitespaceChars) { }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. By default trims the blank spaces and tabs.</summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> public FieldTrimAttribute(TrimMode mode) : this(mode, new char[] { ' ', '\t' }) { }
} // end of SlantVert /// <summary> /// 修整 /// </summary> /// <param name="b">位图流</param> /// <param name="trimAway">修整范围</param> /// <returns></returns> public Bitmap Trim(Bitmap b, TrimMode trimAway) { int width = b.Width; int height = b.Height; // 原始图像大小 int area = width * height; BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); int stride = data.Stride; System.IntPtr scan0 = data.Scan0; int offset = stride - width * BPP; // 修整后的有效区域 int rectTop = 0; int rectBottom = height; int rectLeft = 0; int rectRight = width; unsafe { byte *p = (byte *)scan0; int i = 1; // 上 if ((trimAway & TrimMode.Top) == TrimMode.Top) { p = (byte *)scan0; i = 1; while (i < area) { if (p[3] != 0) { // 获取上边界 rectTop = i / width; break; } p += BPP; if (i % width == 0) { p += offset; } i++; } // while } // 下 if ((trimAway & TrimMode.Bottom) == TrimMode.Bottom) { p = (byte *)scan0 + (height - 1) * stride + (width - 1) * BPP; i = 1; while (i < area) { if (p[3] != 0) { // 获取下边界 rectBottom = height - i / width; break; } p -= BPP; if (i % width == 0) { p -= offset; } i++; } // while } // 左 if ((trimAway & TrimMode.Left) == TrimMode.Left) { p = (byte *)scan0; i = 1; while (i < area) { if (p[3] != 0) { // 获取左边界 rectLeft = i / height; break; } p += stride; if (i % height == 0) { p = (byte *)scan0; p += (i / height) * BPP; } i++; } // while } // 右 if ((trimAway & TrimMode.Right) == TrimMode.Right) { p = (byte *)scan0 + (width - 1) * BPP; i = 1; while (i < area) { if (p[3] != 0) { // 获取右边界 rectRight = width - i / height; break; } p += stride; if (i % height == 0) { p = (byte *)scan0 + (width - 1) * BPP; p -= (i / height) * BPP; } i++; } // while } } b.UnlockBits(data); // 修整有效区域后的图像 Bitmap dst = new Bitmap(rectRight - rectLeft, rectBottom - rectTop); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dst); g.DrawImage(b, new Rectangle(0, 0, dst.Width, dst.Height), new Rectangle(rectLeft, rectTop, dst.Width, dst.Height), GraphicsUnit.Pixel ); g.Save(); b.Dispose(); return(dst); } // end of Trim
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. </summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> /// <param name="chars">A list of chars used to trim.</param> public FieldTrimAttribute(TrimMode mode, params char[] chars) { mTrimMode = mode; mTrimChars = chars; }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. </summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> /// <param name="chars">A list of chars used to trim.</param> public FieldTrimAttribute(TrimMode mode, params char[] chars) { TrimMode = mode; Array.Sort(chars); TrimChars = chars; }
public void FillFieldDefinition(NetLanguage leng, StringBuilder sb, bool properties) { AddMainAttributes(leng, sb); if (TrimMode != TrimMode.None) { switch (leng) { case NetLanguage.VbNet: sb.Append(IndentString); sb.AppendLine("<FieldTrim(TrimMode." + TrimMode.ToString() + ")> "); break; case NetLanguage.CSharp: sb.Append(IndentString); sb.AppendLine("[FieldTrim(TrimMode." + TrimMode.ToString() + ")]"); break; default: break; } } if (mIsOptional == true) { switch (leng) { case NetLanguage.VbNet: sb.Append(IndentString); sb.AppendLine("<FieldOptional()> _"); break; case NetLanguage.CSharp: sb.Append(IndentString); sb.AppendLine("[FieldOptional()]"); break; default: break; } } if (sb.ToString(sb.Length - 2, 2) != Environment.NewLine) { sb.AppendLine(); } sb.Append(IndentString); string visi = EnumHelper.GetVisibility(leng, mVisibility); string usedname; usedname = this.Name; if (properties) { usedname = "m" + this.Name; visi = EnumHelper.GetVisibility(leng, NetVisibility.Private); } switch (leng) { case NetLanguage.VbNet: sb.AppendLine(visi + " " + usedname + " As " + this.Type); break; case NetLanguage.CSharp: sb.AppendLine(visi + " " + this.Type + " " + usedname + ";"); break; default: break; } sb.AppendLine(); }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. By default trims the blank spaces and tabs.</summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> public FieldTrimAttribute(TrimMode mode) : this(mode, WhitespaceChars) { }
internal RestoreTicket TrimDownAndRemoveGlyphBuildingDetail() { switch (_typefaceTrimMode) { default: throw new NotSupportedException(); case TrimMode.EssentailLayoutInfo: return(null); //same mode case TrimMode.Restored: case TrimMode.No: { RestoreTicket ticket = new RestoreTicket(); ticket.TypefaceName = Name; ticket.Headers = _tblHeaders; //a copy //FROM:GlyphLoadingMode.Full => TO: GlyphLoadingMode.EssentailLayoutInfo ticket.HasTtf = _hasTtfOutline; //cache glyph name before unload if (_cff1FontSet != null) { ticket.HasCff = true; UpdateCff1FontSetNamesCache(); //*** _cff1FontSet = null; } //1.Ttf and Otf => clone each glyphs in NO building Glyph[] newClones = new Glyph[_glyphs.Length]; for (int i = 0; i < newClones.Length; ++i) { newClones[i] = Glyph.Clone_NO_BuildingInstructions(_glyphs[i]); } _glyphs = newClones; //and since glyph has no building instructions in this mode //so ... ticket.ControlValues = ControlValues != null; ControlValues = null; ticket.PrepProgramBuffer = PrepProgramBuffer != null; PrepProgramBuffer = null; ticket.FpgmProgramBuffer = FpgmProgramBuffer != null; FpgmProgramBuffer = null; ticket.CPALTable = CPALTable != null; CPALTable = null; ticket.COLRTable = COLRTable != null; COLRTable = null; ticket.GaspTable = GaspTable != null; GaspTable = null; // //3. Svg=> remove SvgTable if (_svgTable != null) { ticket.HasSvg = true; _svgTable.UnloadSvgData(); _svgTable = null; } //4. Bitmap Font => remove embeded bitmap data if (_bitmapFontGlyphSource != null) { ticket.HasBitmapSource = true; _bitmapFontGlyphSource.UnloadCBDT(); } _typefaceTrimMode = TrimMode.EssentailLayoutInfo; return(ticket); } } }
/// <summary>Indicates the <see cref="TrimMode"/> used after read to truncate the field. </summary> /// <param name="mode">The <see cref="TrimMode"/> used after read.</param> /// <param name="trimChars">A string of chars used to trim.</param> public FieldTrimAttribute(TrimMode mode, string trimChars) : this(mode, trimChars.ToCharArray()) { }
/// <summary> /// удалить вхождения строки в начале исходной строки /// </summary> /// <param name="sourceString">исходная строка</param> /// <param name="stringToTrim">удаляемая строка</param> /// <param name="mode"></param> /// <returns>строка с отсутствием заданной строки в начале</returns> public static string TrimStart(this string sourceString, string stringToTrim, TrimMode mode = TrimMode.None) { int charactersToTrim = GetCharactersToTrimStart(sourceString, stringToTrim, mode); return(sourceString.Substring(charactersToTrim)); }