示例#1
0
文件: OcadImport.cs 项目: jonc/carto
        // Create the grid text symbols,
        void CreateGridText(SizeF size, Matrix matrix, float angle, int cxCells, int cyCells, float width, float height, RectangleInfo rectinfo, List<Symbol> symlist)
        {
            PointF[] pts = new PointF[1];

            for (int y = 0; y < cyCells; ++y)
                for (int x = 0; x < cxCells; ++x) {
                    int cellNum;
                    string cellText;

                    if (rectinfo.numberFromBottom)
                        cellNum = y * cxCells + x + 1;
                    else
                        cellNum = (cyCells - 1 - y) * cxCells + x + 1;

                    if (cellNum > cxCells * cyCells - rectinfo.unnumberedCells)
                        cellText = rectinfo.unnumberedText;
                    else
                        cellText = cellNum.ToString();

                    pts[0] = new PointF((x + 0.07F) * width, (y + 1 - 0.04F) * height);
                    pts[0].Y -= rectinfo.gridText.FontAscent - rectinfo.gridText.FontEmHeight;
                    pts = GraphicsUtil.TransformPoints(pts, matrix);

                    TextSymbol sym = new TextSymbol(rectinfo.gridText, new string[] {cellText}, pts[0], angle, 0);
                    symlist.Add(sym);
                }
        }
示例#2
0
文件: OcadExport.cs 项目: jonc/carto
        OcadCoord[] GetTextObjectCoords(TextSymbol sym)
        {
            TextSymDef symdef = ((TextSymDef) sym.Definition);
            PointF location = sym.Location;
            SizeF size = sym.TextSize;
            float angle = sym.Rotation;
            float width = sym.Width;

            PointF[] points;

            if (width > 0) {
                // Formatted text
                points = new PointF[4];
                float topAdjust = symdef.FontEmHeight - (symdef.FontAscent + symdef.FontDescent);
                float height = size.Height + symdef.FontEmHeight - symdef.FontAscent;
                location.Y -= (float) (topAdjust * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (topAdjust * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[3] = location;
                location.Y -= (float) (width * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X += (float) (width * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[2] = location;
                location.Y -= (float) (height * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (height * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[1] = location;
                location.Y += (float) (width * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (width * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[0] = location;
            }
            else {
                // Unformatted text
                float topAdjust = symdef.FontAscent;
                float height = symdef.FontEmHeight;
                float descent = symdef.FontDescent;
                points = new PointF[5];

                location.Y -= (float) (topAdjust * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (topAdjust * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[0] = location;
                location.Y -= (float) (descent * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (descent * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                if (symdef.FontAlignment == TextSymDefAlignment.Right) {
                    location.Y += (float) (size.Width * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                    location.X -= (float) (size.Width * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                }
                else if (symdef.FontAlignment == TextSymDefAlignment.Center) {
                    location.Y += (float) ((size.Width/2) * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                    location.X -= (float) ((size.Width/2) * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                }
                points[1] = location;
                location.Y -= (float) (size.Width * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X += (float) (size.Width * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[2] = location;
                location.Y += (float) ((descent+height) * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X += (float) ((descent+height) * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[3] = location;
                location.Y += (float) (size.Width * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));
                location.X -= (float) (size.Width * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
                points[4] = location;
            }

            OcadCoord[] coords = new OcadCoord[points.Length];
            for (int i = 0; i < coords.Length; ++i)
                coords[i] = OcadCoordFromPoint(points[i]);

            return coords;
        }