本文整理汇总了C#中System.Drawing.CharacterRange类的典型用法代码示例。如果您正苦于以下问题:C# CharacterRange类的具体用法?C# CharacterRange怎么用?C# CharacterRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterRange类属于System.Drawing命名空间,在下文中一共展示了CharacterRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DwellOnIdentifierEventArgs
/// <summary>
/// Creates DwellOnIdentifierEventArgs instance with read-only values set
/// </summary>
/// <param name="identifier"></param>
/// <param name="identifierRange"></param>
/// <param name="visibleRange"></param>
/// <param name="visibleText"></param>
public DwellOnIdentifierEventArgs(string identifier, CharacterRange identifierRange, CharacterRange visibleRange, string visibleText)
{
Identifier = identifier;
IdentifierRange = identifierRange;
VisibleRange = visibleRange;
VisibleText = visibleText;
}
开发者ID:HTD,项目名称:TraxCodeEditor,代码行数:14,代码来源:DwellOnIdentifierEventArgs.cs
示例2: MeasureString
public static SizeF MeasureString(Graphics g, string str, Font font, Rectangle rect, StringFormat sf)
{
var sfTemp = sf.Clone() as StringFormat;
var ranges = new CharacterRange[] { new CharacterRange(0, str.Length) };
sfTemp.SetMeasurableCharacterRanges(ranges);
var regions = g.MeasureCharacterRanges(str, font, rect, sfTemp);
if (regions != null && regions.Length > 0) return regions[0].GetBounds(g).Size;
return new SizeF();
}
开发者ID:cmrazek,项目名称:ProbeNpp,代码行数:10,代码来源:Util.cs
示例3: Word
public Word(CharacterRange range, string text)
{
if (text == null)
throw new ArgumentNullException("text");
Debug.Assert(text.Length > 0);
_range = range;
_text = text;
}
开发者ID:modulexcite,项目名称:NTranslate,代码行数:10,代码来源:SpellCheckTextBox.Word.cs
示例4: findCharacterPositionInPart
private int findCharacterPositionInPart(DocumentRow row, StylizedRowElement atom, float offset)
{
int farLength = atom.range.Length;
int nearLength = 0;
CharacterRange range = new CharacterRange(0, farLength);
string test = row.Raw.Substring(range.First, range.Length);
float nearSize = 0;
float farSize = MeasureStringPart(range, test, atom.style).Size.Width;
if (nearSize > offset) return nearLength;
if (farSize < offset) return farLength - 1;
while (farLength > nearLength)
{
if (farSize < offset)
{
break;
}
if (nearSize > offset)
{
farLength = nearLength;
break;
}
range = new CharacterRange(0, nearLength + (farLength - nearLength) / 2);
test = row.Raw.Substring(range.First, range.Length);
float middle = MeasureStringPart(range, test, atom.style).Size.Width;
if (middle < offset)
{
if (nearLength == range.Length)
{
return farSize - middle > middle - nearSize ? nearLength : farLength;
}
nearLength = range.Length;
nearSize = middle;
}
else
{
if (farLength == range.Length)
{
return farSize - middle > middle - nearSize ? nearLength : farLength;
}
farLength = range.Length;
farSize = middle;
}
}
return farLength;
}
开发者ID:sjeyaram,项目名称:partcover.net4,代码行数:55,代码来源:DocumentView.mouse.cs
示例5: GetTextSize
private static SizeF GetTextSize(string str, Graphics g, bool fTitle) {
SizeF empty = SizeF.Empty;
CharacterRange[] ranges = new CharacterRange[] { new CharacterRange(0, str.Length) };
sfMeasure.SetMeasurableCharacterRanges(ranges);
Region[] regionArray = g.MeasureCharacterRanges(str, fTitle ? font : fontSubText, rctMeasure, sfMeasure);
using(regionArray[0]) {
empty = regionArray[0].GetBounds(g).Size;
empty.Width += 6f;
}
return empty;
}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:11,代码来源:QTabItemBase.cs
示例6: EMFStringFormat
private EMFStringFormat(byte[] RecordData)
{
ObjectType = EmfObjectType.stringformat;
myStringFormat = new System.Drawing.StringFormat();
//put the Data into a stream and use a binary reader to read the data
MemoryStream _ms = new MemoryStream(RecordData);
BinaryReader _br = new BinaryReader(_ms);
_br.ReadUInt32(); //Who cares about version..not me!
myStringFormat.FormatFlags = (StringFormatFlags)_br.ReadUInt32();
_br.ReadBytes(4);//Language...Ignore for now!
myStringFormat.LineAlignment = (StringAlignment)_br.ReadUInt32();
myStringFormat.Alignment = (StringAlignment)_br.ReadUInt32();
UInt32 DigitSubstitutionMethod = _br.ReadUInt32();
UInt32 DigitSubstitutionLanguage = _br.ReadUInt32();
myStringFormat.SetDigitSubstitution((int)DigitSubstitutionLanguage, (StringDigitSubstitute)DigitSubstitutionMethod);
Single FirstTabOffSet = _br.ReadSingle();
myStringFormat.HotkeyPrefix = (System.Drawing.Text.HotkeyPrefix) _br.ReadInt32();
_br.ReadSingle();//leading Margin
_br.ReadSingle();//trailingMargin
_br.ReadSingle();//tracking
myStringFormat.Trimming = (StringTrimming)_br.ReadUInt32();
Int32 TabStopCount = _br.ReadInt32();
Int32 RangeCount = _br.ReadInt32();
//Next is stringformatdata...
Single[] TabStopArray;
System.Drawing.CharacterRange[] RangeArray;
if (TabStopCount > 0)
{
TabStopArray = new Single[TabStopCount];
for (int i = 0; i < TabStopCount; i++)
{
TabStopArray[i] = _br.ReadSingle();
}
myStringFormat.SetTabStops(FirstTabOffSet, TabStopArray);
}
if (RangeCount > 0)
{
RangeArray = new System.Drawing.CharacterRange[RangeCount];
for (int i = 0; i < RangeCount; i++)
{
RangeArray[i].First = _br.ReadInt32();
RangeArray[i].Length = _br.ReadInt32();
}
myStringFormat.SetMeasurableCharacterRanges(RangeArray);
}
}
开发者ID:JackWangCUMT,项目名称:rdlc.report.engine,代码行数:51,代码来源:EMFStringFormat.cs
示例7: GetTextSize
public static Size GetTextSize(Graphics graphics, string text, Font font, Size size)
{
if (text.Length == 0)
{
return Size.Empty;
}
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.FitBlackBox;
RectangleF layoutRect = new RectangleF(0f, 0f, size.Width, size.Height);
CharacterRange[] ranges = new CharacterRange[] {new CharacterRange(0, text.Length)};
Region[] regionArray = new Region[1];
stringFormat.SetMeasurableCharacterRanges(ranges);
Rectangle rectangle =
Rectangle.Round(graphics.MeasureCharacterRanges(text, font, layoutRect, stringFormat)[0].GetBounds(graphics));
return new Size(rectangle.Width, rectangle.Height);
}
开发者ID:NanQi,项目名称:demo,代码行数:16,代码来源:TextUtil.cs
示例8: GetCharacterXPositions
public float[] GetCharacterXPositions( Graphics g, string str )
{
// Setup the StringFormat with proper CharacterRange references.
StringFormat testFormat = new StringFormat();
CharacterRange[] ranges = new CharacterRange[ str.Length ];
for ( int i=0; i < str.Length; i++ )
ranges[i] = new CharacterRange( i, 1 );
testFormat.SetMeasurableCharacterRanges( ranges );
// Measure into Regions
Region[] regions = g.MeasureCharacterRanges( str, _font, new Rectangle( 0, 0, 1000, 1000 ), testFormat );
// Convert Regions to Rects, then X coords.
float[] xCoords = regions.Select( region => region.GetBounds( g ).X ).ToArray();
return xCoords;
}
开发者ID:SudoMike,项目名称:SudoFont,代码行数:17,代码来源:DotNetFontSystem.cs
示例9: getDrawLength
private static int getDrawLength(Graphics g, Font fnt, RectangleF rect, StringFormat sf, int maxLen)
{
CharacterRange[] ranges = new CharacterRange[] { new CharacterRange(0, 1) };
float num = 1f;
float width = 0f;
int num3 = 2;
string text = StrFunc.CreateInstance().MakeCycleStr(maxLen, "X");
while ((num3 <= maxLen) && (width != num))
{
num = width;
ranges[0].Length = num3;
sf.SetMeasurableCharacterRanges(ranges);
width = g.MeasureCharacterRanges(text, fnt, rect, sf)[0].GetBounds(g).Width;
num3++;
}
if (num3 == maxLen)
{
return maxLen;
}
return (num3 - 1);
}
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:21,代码来源:ComponentProperty.cs
示例10: FaceApplied
public FaceApplied(string face, CharacterRange range)
{
this.face = face;
this.range = range;
}
开发者ID:sjeyaram,项目名称:partcover.net4,代码行数:5,代码来源:Document.style.cs
示例11: intersect
private static bool intersect(CharacterRange lhs, CharacterRange rhs)
{
var min = Math.Max(lhs.First, rhs.First);
var max = Math.Min(lhs.First + lhs.Length, rhs.First + rhs.Length);
return min < max;
}
开发者ID:sjeyaram,项目名称:partcover.net4,代码行数:6,代码来源:Document.style.cs
示例12: combine
private StylizedRowElement[] combine(DocumentRow row, ICollection<FaceApplied> styles)
{
if (styles == null || styles.Count == 0)
{
var result = new StylizedRowElement[1];
result[0] = new StylizedRowElement(new CharacterRange(0, row.Length), style);
return result;
}
var elements = new List<CharacterRange>
{
new CharacterRange(0, row.Length)
};
foreach (var styleApplied in styles)
{
var faceRange = styleApplied.Range;
for (var i = 0; i < elements.Count; ++i)
{
CharacterRange element = elements[i];
//if we are before range needed
if (element == faceRange)
{
continue;
}
if (element.First + element.Length < faceRange.First)
{
continue;
}
// if we are after range needed
if (element.First >= faceRange.First + faceRange.Length)
{
break;
}
// if face range after element start
if (element.First < faceRange.First)
{
var preFace = new CharacterRange(element.First, faceRange.First - element.First);
element.Length -= preFace.Length;
element.First += preFace.Length;
elements[i] = element;
elements.Insert(i++, preFace);
}
if (element.First + element.Length <= faceRange.First + faceRange.Length)
{
continue;
}
var afterOffset = faceRange.First + faceRange.Length;
var afterOffsetLength = element.First + element.Length - afterOffset;
element.Length -= afterOffsetLength;
elements[i] = element;
elements.Insert(++i, new CharacterRange(afterOffset, afterOffsetLength));
}
}
var els = new List<StylizedRowElement>();
foreach (var range in elements)
{
var rangeStyle = Style;
foreach (var face in styles)
{
if (!intersect(face.Range, range))
continue;
rangeStyle = rangeStyle.Combine(FindFace(face.Face).FaceStyle);
}
els.Add(new StylizedRowElement(range, rangeStyle));
}
return els.ToArray();
}
开发者ID:sjeyaram,项目名称:partcover.net4,代码行数:82,代码来源:Document.style.cs
示例13: StylizedRowElement
public StylizedRowElement(CharacterRange range, Style style)
{
this.range = range;
this.style = style;
}
开发者ID:sjeyaram,项目名称:partcover.net4,代码行数:5,代码来源:Document.style.cs
示例14: TextSize
/// <summary>
/// Calculate widthLimit/height of a text (
/// </summary>
public static SizeF TextSize(Graphics g, string aText, Font aFont)
{
if (aText.Trim() == "") return new SizeF(0, 0);
if (aText[aText.Length - 1] == ' ') { aText = aText.Substring(0, aText.Length - 1) + "/"; }
#if CF
return TextSize2(g, aText, aFont);
#else
try
{
if (aFont.Style == FontStyle.Bold)
{ return TextSize2(g, aText, aFont); } //MeasureCharacterRanges return wrong value if bold.
StringFormat aFormat = StringFormat.GenericTypographic;
//aFormat.Trimming = System.Drawing.StringTrimming.Character;
//aFormat.FormatFlags += 16384;
//aFormat.FormatFlags = aFormat.FormatFlags & StringFormatFlags.NoClip;
CharacterRange[] cr = new CharacterRange[1];
cr[0] = new CharacterRange(0, aText.Length);
aFormat.SetMeasurableCharacterRanges(cr);
RectangleF aRect = Screen.PrimaryScreen.Bounds;
aRect = g.MeasureCharacterRanges(aText, aFont, aRect, aFormat)[0].GetBounds(g);
return new SizeF(aRect.Right - aRect.Left, aRect.Height);
}
catch
{
return TextSize2(g, aText, aFont);
}
#endif
}
开发者ID:sinelaw,项目名称:HtmlTextBlock,代码行数:36,代码来源:Utils.cs
示例15: RenderRowView
private void RenderRowView(
Graphics g,
DocumentRowView view,
float offset,
CharacterRange selectionRange)
{
for (int i = 0; i < view.parts.Length; ++i)
{
StylizedRowElement atom = view.parts[i];
string atomRaw = view.partRaws[i];
CharacterRangeTrio trio = intersectAtomWithSelection(atom.range, selectionRange);
if (trio.first.Length > 0)
{
trio.first.First -= atom.range.First;
offset += DrawStringPart(trio.first, g, atomRaw, atom.style, offset).Width;
}
if (trio.second.Length > 0)
{
trio.second.First -= atom.range.First;
Style thisStyle = atom.style.combine(selectionStyle);
offset += DrawStringPart(trio.second, g, atomRaw, thisStyle, offset).Width;
}
if (trio.third.Length > 0)
{
trio.third.First -= atom.range.First;
offset += DrawStringPart(trio.third, g, atomRaw, atom.style, offset).Width;
}
}
renderStuff.LineFrame = offset;
}
开发者ID:killbug2004,项目名称:partcover-fork,代码行数:37,代码来源:DocumentView.draw.cs
示例16: MeasureString
/// <summary>
/// Measures the location of an arbritrary # of words within a string
/// </summary>
private WordStartFinish[] MeasureString(string s, Graphics g, Font drawFont, StringFormat drawFormat, CharacterRange[] cra)
{
if (cra.Length <= MEASUREMAX) // handle the simple case of < MEASUREMAX words
return MeasureString32(s, g, drawFont, drawFormat, cra);
// Need to compensate for SetMeasurableCharacterRanges limitation of 32 (MEASUREMAX)
int mcra = (cra.Length / MEASUREMAX); // # of full 32 arrays we need
int ip = cra.Length % MEASUREMAX; // # of partial entries needed for last array (if any)
WordStartFinish[] sz = new WordStartFinish[cra.Length]; // this is the final result;
float startPos=0;
CharacterRange[] cra32 = new CharacterRange[MEASUREMAX]; // fill out
int icra=0; // index thru the cra
for (int i=0; i < mcra; i++)
{
// fill out the new array
int ticra = icra;
for (int j=0; j < cra32.Length; j++)
{
cra32[j] = cra[ticra++];
cra32[j].First -= cra[icra].First; // adjust relative offsets of strings
}
// measure the word locations (in the new string)
// ???? should I put a blank in front of it??
string ts = s.Substring(cra[icra].First,
cra[icra + cra32.Length-1].First + cra[icra + cra32.Length-1].Length - cra[icra].First);
WordStartFinish[] pos = MeasureString32(ts, g, drawFont, drawFormat, cra32);
// copy the values adding in the new starting positions
for (int j = 0; j < pos.Length; j++)
{
sz[icra].start = pos[j].start + startPos;
sz[icra++].end = pos[j].end + startPos;
}
startPos = sz[icra-1].end; // reset the start position for the next line
}
// handle the remaining character
if (ip > 0)
{
// resize the range array
cra32 = new CharacterRange[ip];
// fill out the new array
int ticra = icra;
for (int j=0; j < cra32.Length; j++)
{
cra32[j] = cra[ticra++];
cra32[j].First -= cra[icra].First; // adjust relative offsets of strings
}
// measure the word locations (in the new string)
// ???? should I put a blank in front of it??
string ts = s.Substring(cra[icra].First,
cra[icra + cra32.Length-1].First + cra[icra + cra32.Length-1].Length - cra[icra].First);
WordStartFinish[] pos = MeasureString32(ts, g, drawFont, drawFormat, cra32);
// copy the values adding in the new starting positions
for (int j = 0; j < pos.Length; j++)
{
sz[icra].start = pos[j].start + startPos;
sz[icra++].end = pos[j].end + startPos;
}
}
return sz;
}
开发者ID:net-haus,项目名称:My-FyiReporting,代码行数:66,代码来源:RenderPdf.cs
示例17: MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical
public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
{
if (font == null)
Assert.Ignore ("Couldn't create required font");
string text = "Hello Mono::";
CharacterRange[] ranges = new CharacterRange[1];
ranges[0] = new CharacterRange (5, 4);
StringFormat string_format = new StringFormat ();
string_format.FormatFlags = StringFormatFlags.DirectionVertical;
string_format.SetMeasurableCharacterRanges (ranges);
using (Bitmap bitmap = new Bitmap (20, 20)) {
using (Graphics g = Graphics.FromImage (bitmap)) {
string_format.LineAlignment = StringAlignment.Near;
Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
Assert.AreEqual (1, regions.Length, "Near.Region");
RectangleF near = regions[0].GetBounds (g);
string_format.LineAlignment = StringAlignment.Center;
regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
Assert.AreEqual (1, regions.Length, "Center.Region");
RectangleF center = regions[0].GetBounds (g);
string_format.LineAlignment = StringAlignment.Far;
regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
Assert.AreEqual (1, regions.Length, "Far.Region");
RectangleF far = regions[0].GetBounds (g);
Assert.IsTrue (near.X < center.X, "near-center/X");
Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
Assert.IsTrue (center.X < far.X, "center-far/X");
Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
}
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:41,代码来源:TestGraphics.cs
示例18: MeasureCharacterRanges
private void MeasureCharacterRanges (string text, int first, int length)
{
if (font == null)
Assert.Ignore ("Couldn't create required font");
CharacterRange[] ranges = new CharacterRange[1];
ranges[0] = new CharacterRange (first, length);
StringFormat string_format = new StringFormat ();
string_format.FormatFlags = StringFormatFlags.NoClip;
string_format.SetMeasurableCharacterRanges (ranges);
using (Bitmap bitmap = new Bitmap (20, 20)) {
using (Graphics g = Graphics.FromImage (bitmap)) {
SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
g.MeasureCharacterRanges (text, font, layout_rect, string_format);
}
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:20,代码来源:TestGraphics.cs
示例19: SetMeasurableCharacterRanges
public void SetMeasurableCharacterRanges(CharacterRange[] ranges)
{
int status = SafeNativeMethods.Gdip.GdipSetStringFormatMeasurableCharacterRanges(new HandleRef(this, this.nativeFormat), ranges.Length, ranges);
if (status != 0)
{
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:StringFormat.cs
示例20: intersect
private static CharacterRange intersect(CharacterRange range1, CharacterRange range2)
{
int start = Math.Max(range1.First, range2.First);
int end = Math.Min(range1.First + range1.Length, range2.First + range2.Length);
if (end > start)
return new CharacterRange(start, end - start);
return new CharacterRange();
}
开发者ID:killbug2004,项目名称:partcover-fork,代码行数:9,代码来源:DocumentView.draw.cs
注:本文中的System.Drawing.CharacterRange类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论