/// <summary> /// Draws the text that is currently being added, together with a rectangle representing /// the outline of the label. /// </summary> /// <param name="refpos">Reference position for the label</param> protected void DrawText(IPosition refpos) { if (refpos == null) { return; } // Draw the outline of the label. IPosition[] outline = GetOutline(refpos); IDrawStyle style = new DrawStyle(); // black style.Render(ActiveDisplay, outline); // Draw the text PointGeometry p = PointGeometry.Create(refpos); IFont font = (m_Entity == null ? null : m_Entity.Font); MiscTextGeometry text = new MiscTextGeometry(m_Text, p, font, m_Height, m_Width, (float)m_Rotation); style.Render(ActiveDisplay, text); // If doing auto-angle stuff, draw an additional line // at the position used to search for candidate lines // ... perhaps (the auto-angle stuff needs to move to // this class from CuiNewLabel) // Remember the specified position as the "last" position. m_LastPos = refpos; }
private Feature ImportName(Ntx.Name name, Operation creator) { /* // Get pointer to the applicable map theme CeTheme theme(Name.GetTheme()); CeTheme* pTheme = theme.AddTheme(); // Get pointer to the entity type. GRAPHICSTYPE geom = ANNOTATION; if ( Name.IsLabel() ) geom = POLYGON; CeEntity* pEntity = AddEntity(Name.GetpFeatureCode(),pTheme,geom); */ IEntity entity = GetEntityType(name, SpatialType.Text); // Get the text string string text = name.Text; // Get the position of the centre of the 1st character Ntx.Position pos = name.Position(0); IPosition vcentre = new Position(pos.Easting, pos.Northing); // Get text metrics float height = name.Height; float spacing = name.Spacing; float rotation = name.Rotation; // Calculate the top left corner of the first character using // the text metrics we just got ... // Get the width of the first character. For names that contain // only one character, the spacing we have will be zero, so in // that case, deduce the width of the character via the covering // rectangle. float charwidth = spacing; if (charwidth < Constants.TINY) { // Get the covering rectangle. Ntx.Position nw = name.NorthWest; Ntx.Position se = name.SouthEast; // And get the dimensions. double dx = se.Easting - nw.Easting; double dy = nw.Northing - se.Northing; // If the cover is screwed up, assume the width is 80% of the text height. if (dy < Constants.TINY) charwidth = (float)(height * 0.8); else charwidth = (float)(height * (dx/dy)); } // Define the bearing from bottom to top of the text. double vbear = (double)rotation; // Get position directly above the centre of the 1st char. IPosition above = Geom.Polar(vcentre, vbear, 0.5 * (double)height); // Define the bearing from the point we just got to the // start of the text string. double hbear = vbear - Constants.PIDIV2; // Back up half a character to get the initial corner. PointGeometry topleft = new PointGeometry(Geom.Polar(above, hbear, 0.5 * (double)charwidth)); IFont font = null; double width = (double)text.Length * charwidth; TextFeature result = null; if (name.IsLabel) { // Create key text string keystr = name.Text; KeyTextGeometry kt = new KeyTextGeometry(topleft, font, height, width, rotation); InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId(); result = new TextFeature(creator, id, entity, kt); kt.Label = result; result.SetTopology(true); // Define the label's foreign ID and form a two-way association ForeignId fid = GetFeatureId(keystr); Debug.Assert(fid != null); fid.Add(result); // Remember the reference position of the label. Ntx.Position xp = name.RefPosition; IPointGeometry pp = new PointGeometry(xp.Easting, xp.Northing); result.SetPolPosition(pp); } else { // Create a miscellaneous text label. MiscTextGeometry mt = new MiscTextGeometry(text, topleft, font, height, width, rotation); InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId(); result = new TextFeature(creator, id, entity, mt); result.SetTopology(false); } return result; }
/// <summary> /// Draws the text that is currently being added, together with a rectangle representing /// the outline of the label. /// </summary> /// <param name="refpos">Reference position for the label</param> protected void DrawText(IPosition refpos) { if (refpos==null) return; // Draw the outline of the label. IPosition[] outline = GetOutline(refpos); IDrawStyle style = new DrawStyle(); // black style.Render(ActiveDisplay, outline); // Draw the text PointGeometry p = PointGeometry.Create(refpos); IFont font = (m_Entity==null ? null : m_Entity.Font); MiscTextGeometry text = new MiscTextGeometry(m_Text, p, font, m_Height, m_Width, (float)m_Rotation); style.Render(ActiveDisplay, text); // If doing auto-angle stuff, draw an additional line // at the position used to search for candidate lines // ... perhaps (the auto-angle stuff needs to move to // this class from CuiNewLabel) // Remember the specified position as the "last" position. m_LastPos = refpos; }