📅  最后修改于: 2023-12-03 15:33:42.952000             🧑  作者: Mango
Plantuml是一款基于文本描述生成UML图的工具,使用简单,功能强大。本文将介绍如何使用Plantuml改变生成的UML图中字体的大小,以及如何将生成的图导出为Html格式。
Plantuml默认的字体大小是14,可以通过以下代码改变字体大小:
@startuml
skinparam defaultFontSize 16
Bob -> Alice : Hello
@enduml
其中, skinparam defaultFontSize 16
表示将默认字体大小改为16,可以根据实际需要自行修改。这段代码会生成以下的UML图:
Plantuml支持将生成的UML图导出为Html格式,代码如下:
@startuml
Bob -> Alice : Hello
@enduml
!define AWSPUML https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWSPUML/AWSCommon.puml
!define AWS_MINIMAL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWS_MINIMAL/AWSCommon.puml
!define AWS_FULL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!define AWS_COLOR #232F3E
!define FONTARIALMONO arial.ttf
!includeurl AWS_FULL/AWSCommon.puml
!define SPRITESURL https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1
!includeurl SPRITESURL/CiscoIcons/CiscoIcons.puml
!define F5ICONURL https://raw.githubusercontent.com/f5devcentral/f5-icons-for-plantuml/v3.6.0/f5-common.puml
!includeurl F5ICONURL
其中,@startuml和@enduml之间的代码是要导出为Html的UML图代码。在导出Html的时候,Plantuml还支持导入一些图标库,以方便用户快速绘制UML图。
为了使用这些图标库,需要在代码中引用:
!define AWSPUML https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWSPUML/AWSCommon.puml
!define AWS_MINIMAL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWS_MINIMAL/AWSCommon.puml
!define AWS_FULL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!define AWS_COLOR #232F3E
!define FONTARIALMONO arial.ttf
!includeurl AWS_FULL/AWSCommon.puml
!define SPRITESURL https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1
!includeurl SPRITESURL/CiscoIcons/CiscoIcons.puml
!define F5ICONURL https://raw.githubusercontent.com/f5devcentral/f5-icons-for-plantuml/v3.6.0/f5-common.puml
!includeurl F5ICONURL
代码中的这些图标库是Plantuml官方提供的,还可以导入其他的图标库。
导出Html的代码如下:
@startuml
Bob -> Alice : Hello
@enduml
!define AWSPUML https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWSPUML/AWSCommon.puml
!includeurl AWSPUML/Containers.puml
!includeurl AWSPUML/SecurityIdentityCompliance.puml
!includeurl AWSPUML/Miscellaneous.puml
!includeurl AWSPUML/ManagementGovernance.puml
!includeurl AWSPUML/Compute.puml
!includeurl AWSPUML/Database.puml
!includeurl AWSPUML/NetworkContentDelivery.puml
!includeurl AWSPUML/Analytics.puml
!includeurl AWS_MINIMAL/Compute.puml
!define AWS_MINIMAL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!includeurl AWS_MINIMAL/AWSCommon.puml
!includeurl AWS_MINIMAL/Containers.puml
!includeurl AWS_MINIMAL/SecurityIdentityCompliance.puml
!includeurl AWS_MINIMAL/ManagementGovernance.puml
!includeurl AWS_MINIMAL/Networking.puml
!includeurl AWS_MINIMAL/Database.puml
!includeurl AWS_MINIMAL/Compute.puml
!includeurl AWS_MINIMAL/Analytics.puml
!define AWS_FULL https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v21.6.0/dist
!define AWS_COLOR #232F3E
!define FONTARIALMONO arial.ttf
!includeurl AWS_FULL/AWSCommon.puml
!define SPRITESURL https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1
!includeurl SPRITESURL/CiscoIcons/CiscoIcons.puml
!includeurl SPRITESURL/CiscoIcons/Routers.puml
!includeurl SPRITESURL/CiscoIcons/Switches.puml
!define F5ICONURL https://raw.githubusercontent.com/f5devcentral/f5-icons-for-plantuml/v3.6.0/f5-common.puml
!includeurl F5ICONURL
!define DDB https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/DynamoDB.puml
!includeurl DDB
!define EKS https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/eks.puml
!includeurl EKS
!define EC2ADMIN https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/ec2-admin.puml
!includeurl EC2ADMIN
!define K8SCLUSTER https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/k8s-cluster.puml
!includeurl K8SCLUSTER
!define SSHKEY https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/ssh-key.puml
!includeurl SSHKEY
!define RDS https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/RDS.puml
!includeurl RDS
!define REDSHIFT https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/redshift.puml
!includeurl REDSHIFT
!define S3 https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/S3.puml
!includeurl S3
!define VPC https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/VPC.puml
!includeurl VPC
!define KINESIS https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/Kinesis.puml
!includeurl KINESIS
!define FIREHOSE https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/Firehose.puml
!includeurl FIREHOSE
!define ECR https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/ecr.puml
!includeurl ECR
!define ECS https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/ecs.puml
!includeurl ECS
!define ELB https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/elbv3.puml
!includeurl ELB
!define R53 https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/r53.puml
!includeurl R53
!define APIGW https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/apigw.puml
!includeurl APIGW
!define CFT https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/CFT.puml
!includeurl CFT
!define TARGETGROUP https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/targetgroup.puml
!includeurl TARGETGROUP
!define KINESISVIDEO https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/kinesis-video.puml
!includeurl KINESISVIDEO
!define REVIEWGITHUB https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/review-github.puml
!includeurl REVIEWGITHUB
!define CLOUDFORMATION https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/cloudformation.puml
!includeurl CLOUDFORMATION
!define LAMBDA https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/Lambda.puml
!includeurl LAMBDA
!define STATEMACHINE https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/states.puml
!includeurl STATEMACHINE
!define CODECOMMIT https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/codecommit.puml
!includeurl CODECOMMIT
!define WORKMAIL https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/workmail.puml
!includeurl WORKMAIL
!define WORKDOCS https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v0.5.1/workdocs.puml
!includeurl WORKDOCS
以上代码中,代表导出的图片为:
本文主要介绍了如何使用Plantuml改变生成的UML图中字体的大小,以及如何将生成的图导出为Html格式。通过学习本文,相信读者能够更加熟练地使用Plantuml工具绘制UML图。