本文整理汇总了C#中System.Drawing.CharacterRange类的典型用法代码示例。如果您正苦于以下问题:C# CharacterRange类的具体用法?C# CharacterRange怎么用?C# CharacterRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterRange类属于System.Drawing命名空间,在下文中一共展示了CharacterRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例3: Word
public Word(CharacterRange range, string text)
{
if (text == null)
throw new ArgumentNullException("text");
Debug.Assert(text.Length > 0);
_range = range;
_text = text;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例10: FaceApplied
public FaceApplied(string face, CharacterRange range)
{
this.face = face;
this.range = range;
}
示例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;
}
示例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();
}
示例13: StylizedRowElement
public StylizedRowElement(CharacterRange range, Style style)
{
this.range = range;
this.style = style;
}
示例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
}
示例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;
}