This contains some C++ example programs that use cairomm and pangomm to render shapes and unicode text into images and PDF, and measure the pixel size of unicode text. These programs run in a Linux docker container.
- Cairomm examples can render circle, line, and reactagle into png and svg, and PDF.
- Pangomm examples can render unicode text like Latin letters, Chinese, Japanese, Emoji, and measure pixel size of unicode text.
-
VS Code Extension: Remote - Containers, for connecting with a docker container
-
VS Code Extension: C/C++, for editing and debugging C++ code
- In VS Code, go to "View > Command Palette...", enter "Remote-Containers: OpenFolder in Container..." and execute the command.
- Navigate to the folder of this repository in your local disk, and open it.
- Now wait for VS Code to finish building the docker image, it will take a while. (Note if VS Code asks about how to build the docker image, just choose to use the Dockerfile.)
- Go to "View > Extentions" to install the "C/C++" extention in the docker container by clicking the "Install in Dev Container: Existing Dockerfile" button. We must reload VS Code after installing this extention, we can just click the "Reload Required" button.
- Go to "View > Terminal" to open the Terminal, and use the commands from section "Build and run C++ examples in docker" to build the program.
- Go to "View > Run" to open the debugger, select "measure-text-pdf", and then launch the program to start debugging.
Run the Dockerfile to build the docker image so that we can compile and run the C++ example programs in it:
docker build --tag cairomm-pangomm-on-linux-docker:1.0 .
docker run -it --rm --name renderer-test -v /path/to/your-local-source-root:/path/to/your-work-directory-in-docker-container cairomm-pangomm-on-linux-docker:1.0 /bin/bash
Here is an example command to run the image in docker:
docker run -it --rm --name renderer-test -v /users/<user>/repositories/cairomm-pangomm-on-linux-docker:/workspaces/cairomm-pangomm-on-linux-docker cairomm-pangomm-on-linux-docker:1.0 /bin/bash
cd /workspaces/cairomm-pangomm-on-linux-docker/examples/pangomm
mkdir -p build && cd build
g++ -g -Wall -o measure-text-pixel-size-pdf `pkg-config --cflags cairomm-1.0 pangomm-1.4` ../measure-text-pixel-size-pdf.cpp `pkg-config --libs cairomm-1.0 pangomm-1.4`
./measure-text-pixel-size-pdf "../unicode-text.txt" "Noto Sans Mono CJK TC"
This is just for improving developers' productivity on Mac writing C++ code in VS Code.
Install the dependencies using brew so that we can navigate through the source code of the third party libraries.
brew install pangomm
brew install pkgconfig
- Drawing ellipse with cairo
- Cairo doesn't support ellipse natively, we have to use a circle to model a ellipse by scalling differently between horizonal and vertical directions. But the problem is that the line width of the ellipse becomes different on horizonal and vertical directions.
- Drawing an embedded image
- Not sure how we can draw an embedded image, need more research.
- Which fonts should we install by default?
- There are too many fonts installed for the examples here, how do we remove the unuseful ones?
- Cairomm: A C++ wrapper for the cairo graphics library
- Pangomm: The official C++ interface for the Pango font layout library
- Docker: Build and run your image
- VS Code: Developing inside a Container
- VS Code: Example of debugging C++ code in docker containers
Unicode texts and their pixel sizes, and some shapes
PNG
SVG