[Shapedotnet-development] Rendering fonts for points instead of ellipses
Status: Beta
Brought to you by:
k5jvc
|
From: Rife, R. <ri...@pw...> - 2004-03-15 14:08:33
|
This is going to be a pain to read but, below is the coded that needs to
be added if you want to be able to render a font character instead of
ellipses for points:
=20
Added to GIS.ShapefileReader.Shapefile.cs
=20
(global vars)
protected bool _renderSymbolFont;
protected Font _symbolFont;
protected int _symbolFontIndex;
(constructor)
_renderSymbolFont =3D false;
_symbolFont =3D new Font( "Tahoma", 8 );
_symbolFontIndex =3D 1;
(other methods added or changed)
private void Highlight(int record_number, Color c)
{
RenderThread drawThread;
Pen tempPen =3D (Pen) _pen.Clone();
tempPen.Color =3D c;
=20
if ( _ShapeType =3D=3D ShapeType.Line )
{
tempPen.Width +=3D 2;
tempPen.StartCap =3D LineCap.RoundAnchor;
tempPen.EndCap =3D LineCap.RoundAnchor;
}
=20
HatchBrush tempBrush =3D new HatchBrush(
HatchStyle.Percent70, c, Color.Transparent );
=20
drawThread =3D new RenderThread( _mapMetrics, =
_features,
_ShapeType, record_number, record_number + 1,
tempPen, tempBrush, _symbolFont, _symbolFontIndex, _renderSymbolFont );
=20
drawThread.Start();
=20
tempPen.Dispose();
tempBrush.Dispose();
}
public void Draw()
{
_mapMetrics.UpdateMetrics();
GenerateDrawList(); =20
=20
for ( int a=3D0; a<NUM_THREADS; ++a )
{
if ( a =3D=3D NUM_THREADS - 1 )
{
drawThreads[ a ] =3D new RenderThread(
_mapMetrics, _features,
_ShapeType, a * threadBoundary,
_features.Length, _pen, _brush, _symbolFont, _symbolFontIndex,
_renderSymbolFont );
}
else
{
drawThreads[ a ] =3D new RenderThread(
_mapMetrics, _features,=20
_ShapeType, a * threadBoundary, (a +
1) * threadBoundary, _pen, _brush, _symbolFont, _symbolFontIndex,
_renderSymbolFont );
}
=20
threads[ a ] =3D new Thread( new ThreadStart(
drawThreads[a].Start ) );
threads[ a ].Start();
}
=20
for ( int b=3D0; b<NUM_THREADS; ++b )
{
threads[b].Join();
}
=20
// if a feature has been highlighted with a query
=20
if ( _highlightedFeature !=3D -1 )
{
this.Highlight( _highlightedFeature,
SystemColors.Highlight );
}
}
=20
public int SymbolFontIndex
{
get
{
return _symbolFontIndex;
}
set
{
_symbolFontIndex =3D value;
}
}
=20
public Font SymbolFont
{
get
{
return _symbolFont;
}
set
{
_symbolFont =3D value;
}
}
=20
public bool RenderSymbolFont
{
get
{
return _renderSymbolFont;
}
set
{
_renderSymbolFont =3D value;
}
}
=20
Added to GIS.ShapefileReader.RenderThread.cs
(global vars)
private Font _symbolFont;
private int _symbolFontIndex;
private bool _renderSymbolFont;
=20
(changed constructor)
public RenderThread( MapMetrics metrics,=20
VectorFeature[] features,
ShapeType type,
int beginning,
int ending,
Pen pen,
Brush brush,
Font symbolFont,
int symbolFontIndex,
bool renderSymbolFont )
{
_mapMetrics =3D metrics;
_features =3D features;
_shapeType =3D type;
_beginningFeature =3D beginning;
_endingFeature =3D ending;
_pen =3D (Pen) pen.Clone();
_brush =3D (Brush) brush.Clone();
_symbolFont =3D symbolFont;
_symbolFontIndex =3D symbolFontIndex;
_renderSymbolFont =3D renderSymbolFont;
_gr =3D Graphics.FromImage( _mapMetrics.Canvas );
}
=20
(changed method)
private void DrawPoints()=20
{ =20
for ( int a =3D_beginningFeature; a<_endingFeature; =
++a
)
{
VectorFeature vf =3D _features[a];
=20
if ( vf.IsInViewport =3D=3D false ) continue; //
Don't draw this feature
=20
for ( int segment=3D0; segment < =
vf.SegmentCount;
++segment )
{
for ( int point=3D0; point <
vf[segment].Length; ++point )
{
if( _renderSymbolFont && _symbolFont
!=3D null && _symbolFontIndex > 0 )
{
=20
System.Drawing.SizeF charSize =3D
_gr.MeasureString(System.Convert.ToChar(_symbolFontIndex).ToString(),
_symbolFont);
if(!charSize.IsEmpty)
=20
_gr.DrawString(System.Convert.ToChar(_symbolFontIndex).ToString(),_symbo
lFont,_brush, vf[segment][point].X - (charSize.Width / 2),
vf[segment][point].Y - (charSize.Height / 2));
}
else
{
_gr.FillEllipse( _brush,
vf[segment][point].X,
vf[segment][point].Y,
_pen.Width, _pen.Width );
=20
_gr.DrawEllipse( new Pen(
_pen.Color, 1 ), vf[segment][point].X,=20
vf[segment][point].Y,
_pen.Width, _pen.Width );
}
}
}
}
=20
_gr.Dispose();
}
=20
Added to GIS.IMapLayer.cs
=20
/// <summary>
/// The font used to render points.
/// </summary>
Font SymbolFont
{
get;
set;
}
=20
/// <summary>
/// The index of the character to use when rendering using
the SymbolFont.
/// </summary>
int SymbolFontIndex
{
get;
set;
}
=20
/// <summary>
/// Determines whether or not to use the SymbolFont to draw
points instead of an ellipse.
/// </summary>
bool RenderSymbolFont
{
get;
set;
}
=20
=20
Ryan Rife
Senior Software Developer
Pacific Western Technologies
(865) 483-0554 x118
=20
"Lucky Charms Has More=20
Marshmallows Than Cat Food."
=20
|