【图形描述语言】Mscgen

本系列介绍 文本转图片 工具支持的图形描述语言。图形描述语言将图片描述为代码或者文本,有利于版本管理,很适合嵌入 LaTeX 或 Markdown 文档。用于网站时,还可以减轻图片存储压力,因为图片可以根据代码在使用时生成。本文是该系列第二篇,介绍 mscgen。

mscgen是什么

Mscgen 是一个小程序,它解析 消息序列图描述 (Message Sequence Chart descriptions)并生成 PNG、SVG、EPS 或服务器端图像映射(ismaps)作为输出。消息序列图(Message Sequence Charts, MSCs)是表示一段时间内实体和交互的一种方式,通常与 SDL 结合使用。虽然 MSCs 的创建和使用并不复杂,但 MSCs 在指定协议如何操作方面在通信领域中很流行。Mscgen 旨在提供一种简单的文本语言,可以清晰地创建、编辑和理解,也可以转换为用于显示或打印的通用图像格式。

语法介绍

消息序列图的一般格式由以下带注释的示例给出。应该注意,输入解析器会忽略空白和换行。

Input fragmentMeaning
# MSC for some fictional process注释。使用 # 或者 // 或者 C 语言风格的块注释 /* ... */
msc {MSC 开始
width = "800";输出控制选项。注意 hscale 选项用于按比例设置宽度
a, b, "c";列出将在消息序列图中使用的实体,按它们在页面中从左到右和水平方向出现的顺序排列。请注意,每个实体名称可以加引号,也可以不加引号,除非该名称包含空格,在这种情况下需要双引号。
a->b指示某个消息从 a 传递到 b。在本例中,命名实体 ab 必须在消息序列图的开始处声明。同样,如果实体名包含空格,则应该使用双引号。
a<-c [label="return"];指示某些消息从 c 传递到 a。在本例中,方括号中还提供了一些属性。label 属性提供写在消息弧之上的文本。
}消息序列图的末尾

语法非常简单。需要注意的重要部分是,第一行给出了消息序列图选项和实体,下面的每一行描述了一个消息弧。下面介绍每种可能的消息弧线类型,包括所谓的“特殊”弧线,这些弧线不显示实体之间的关系,而是在图表上水平地描述一些内容。

消息类型

mscgen消息类型
mscgen消息类型

框类型允许添加状态框和条件框。在源中,这些仍然表示为实体之间的关系,但在本例中,框的作用是从源扩展到目标实体。

Example MSC using boxes
Example MSC using boxes

属性

除了 arc 类型之外,还可以为每个消息 arc 或实体提供少量属性。这些属性放在方括号中,在实体名或消息弧之后立即分开,属性将被附加到这些实体名或消息弧上:

下表描述了所有可能的属性及其含义,注意到每个属性都可以为特殊的 --- arc 类型,以及任何其他 arc 或实体。

Source AttributeMeaning
labelA label to place on the message arc, or label to use for an entity. This is reproduced literally above the message arc or in place of the entity name. When used as a message arc label this may also contain parameters or required text. If a \n is encountered, it will be interpreted as a newline, placing text below the arc as well as above it in the normal position, or expanding entity tiles onto more lines.
URLWhen generating the image, colour the label in blue. If generating an image map, create an entry for the label to the specified URL. If the message sequence chart is to be embedded in Doxygen documentation, the URL maybe specified as \ref xxx where xxx is the name of some documented element; in this case a link to the element will automatically be made.
IDAdds a superscript identifier to the label. Typically this maybe a number such that specific elements can be identified and referred to in surrounding descriptive text.
IDURLSimilar to the URL attribute, but links from the ID text rather than the message label. This has the same semantics as the URL attribute, but is only of use if an arc also has an ID.
arcskipThis offsets the vertical position at which an arc reaches its destination entity.
linecolour, linecolorFor arcs or entities, set the line to the specified colour.
textcolour, textcolorFor arcs or entities, set label text to the specified colour.
textbgcolour, textbgcolorFor arcs or entities, set a colour for the text background block. Sets the fill colour for 'box', 'abox', 'rbox' and 'note' shapes.
arclinecolour, arclinecolorOnly meaningful on a entity, this sets the default line colour for all arcs that originating from that entity. This can be overridden by linecolour attributes on specific arcs as desired.
arctextcolour, arctextcolorOnly meaningful on a entity, this sets the default text colour for all arcs that originating from that entity. This can be overridden by textcolour attributes on specific arcs as desired.
arctextbgcolour, arctextbgcolorOnly meaningful on a entity, this sets the default colour for the text background for all arc oriniationg from that entity. This can be overridden by textbgcolour attributes on specific arcs as desired.

颜色可以指定为 RGB 颜色代码,使用 # 前缀作为每个 HTML 标记,也可以使用一些预定义的颜色名称,如下例所示。

NameCode
white#ffffff
silver#c0c0c0
gray#808080
black#000000
maroon#800000
red#ff0000
orange#ffb000
yellow#ffff00
olive#808000
green/lime#00ff00
aqua#00ffff
teal#008080
blue#0000ff
navy#000080
indigo#440088
purple#800080
violet#d02090
fuchsia#ff00ff
mscgen 颜色效果
mscgen 颜色效果

选项

最后,可以将选项添加到输入文件中,以控制生成的图像的各个方面。目前只支持几个选项,并且必须在输入文件的顶部给出,如下面的示例所示。表中描述了允许的选项。

OptionMeaning
hscaleScale the image width by this factor, which must be a non-zero value. Normally the output width is 600 pixels for a PNG, but can be scaled to any value by specifying fractional multipliers. For example, specifying a value of 1.5 would set the width to 600 x 1.5 = 900 pixels.
widthSet the image width to this values, which must be non-zero and is given in pixels. This can be used instead of the hscale option, in cases where the explicit image width is preferred to a scale factor.
arcgradientThis causes message arcs to slope down the page rather than running horizontally. The value given is the number of pixels below the start of the message arc that the end of the arc should meet the target entity.
wordwraparcsIf set to 'true', 'on' or '1', this will cause long lines of text on arrow arcs to be automatically word wrapped. By default word wrapping is only enabled for 'box', 'abox', 'rbox' and 'note' style arcs.

mscgen画廊

MSC for some fictional process
MSC for some fictional process
Fictional client-server protocol
Fictional client-server protocol
TCP 三次握手
TCP 三次握手

以上就是全部内容,欢迎到 文本转图片工具 试用。

请勿全文转载,部分引用请注明出处。
本文链接地址: https://www.annhe.net/article-4117.html
博客能带货吗

发表评论

电子邮件地址不会被公开。 必填项已用*标注