定制 4dd/m2vec 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

4dd/m2vec

最新稳定版本:1.1.1

Composer 安装命令:

composer create-project 4dd/m2vec

包简介

Metro2 VEC to SVG converter

README 文档

README

A command-line tool that converts .vec files into SVG. The VEC format is a custom line-based vector format used by the pMetro program for station schemes. This tool produces SVG output that visually matches what the native viewer renders.

Installation

Requires PHP 8.4+ and Composer.

Global install (recommended):

composer global require 4dd/m2vec

Make sure ~/.config/composer/vendor/bin (or ~/.composer/vendor/bin) is in your PATH.

Local install:

composer require 4dd/m2vec
./vendor/bin/m2vec path/to/scheme.vec path/to/scheme.svg

Usage

Convert a single file:

m2vec path/to/scheme.vec path/to/scheme.svg

Batch-convert a list of source|destination pairs (one per line, # for comments, - to read from stdin):

m2vec --batch=jobs.txt

VEC format overview

A .vec file is a sequence of one-line commands. Tokens are separated by spaces or commas (interchangeably). Numbers are integers or decimals; coordinates are in pixels with the origin at the top-left.

The file is cp1251-encoded; m2vec converts every line to UTF-8 once and the rest of the pipeline operates in UTF-8.

Comments

Lines starting with ;, =, -, or : are treated as comments and rendered into the SVG as <!-- ... -->. The documented prefix is ; only; the others appear throughout the corpus as visual separators (===), hand-disabled commands (--Line ...) and a typo in several spb files (:). The native viewer ignores all of them, so we do too.

Drawing-state commands

CommandEffect on subsequent commands
Size WxHCanvas dimensions in pixels. Required, must appear once.
PenColor RRGGBBStroke colour (hex). -1 means "no stroke" (transparent).
BrushColor RRGGBBFill colour. -1 means "no fill" (transparent).
Angle degRotates the entire remaining canvas around its centre.
Opaque pctOpens a translucent group at pct% opacity. Opaque 100 closes the group AND resets pen+brush to defaults — the native viewer scopes drawing state inside an opaque block.
Image pathEmbeds an external raster image as an <image> element.

Geometry commands

All shape commands optionally accept a trailing odd-token "stroke width" after the coordinate pairs.

CommandArgumentsSVG output
Linex1,y1, x2,y2[, ...xn,yn][, w]<polyline> (stroke only)
Dashedsame as Line<polyline> with stroke-dasharray
Spline2+ points, optional width<polyline> refined by 4-point interpolating subdivision (8 inserted vertices per input segment)
Polygon3+ points, optional width<polygon> with current pen + brush
Stairsp1, p2, p3[, w] (3 points define a parallelogram)A polyline of stair "rungs" perpendicular to the p1→p2 edge, inset by half a step on both ends
Arrow2+ points, optional widthA <polyline> shaft plus an arrowhead at the last point (rotated to match the final segment)
Ellipsex1,y1, x2,y2[, w] (bounding box corners)<ellipse>
RailwayrailW, sleeperW, step, x1,y1, ...xn,yn[, w]Two parallel polyline rails (same subdivision as Spline) plus perpendicular sleepers at step/2, 3·step/2, ...

Text commands

CommandArgumentsSVG output
TextOutfont, size, x, y, text[, styleFlag]<text> with font-family, font-size and style attrs
AngleTextOutangle, font, size, x, y, text[, styleFlag]<text> wrapped in a transform="rotate(...)" group

Notes on text:

  • The text field may be wrapped in single or double quotes ('...' or "...") to preserve embedded commas. The wrapping quotes are stripped from the output.
  • Literal \n (backslash + n) inside the text becomes a <tspan> line break with dy="1.2em".
  • styleFlag is a bitmask in [1, 15]: 1 = bold, 2 = italic, 4 = underline, 8 = strikethrough (combinable).
  • Font size is divided by 1.2 before emitting, which empirically matches the native viewer's rendering at typical sizes.

Interactive / spot commands

These are flagged regions used by the original viewer for click handlers. m2vec renders them as plain visible shapes (without the click target).

CommandArgumentsSVG output
SpotRectx, y, width, height[, action]<rect> with current pen + brush
SpotCircler, x, y[, action]<circle> filled only (no stroke)

The pMetro readme documents SpotCircle as x, y, r, but every real file uses r, x, y and the native viewer follows that order — m2vec matches the data.

What is NOT supported

  • Action handlers on Spot commands. The action field (typically ShowMessage ...) is parsed but not emitted; the SVG is static.
  • Viewer-only metadata like raw byte-level encoding artefacts beyond cp1251.
  • Custom fonts. The font field is passed through to font-family; the rendering depends on the consumer's available fonts.

Error handling

Invalid lines are never fatal. They become:

  1. A [WARN] file:line — message line on stderr.
  2. An inline <!-- Warning: ... --> comment in the SVG at the same position.

Unknown commands, malformed coordinates, and missing required fields are all reported this way so that one bad line never blocks the rest of the file.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固