Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qr-fonts): implement ibm plex sans for qrcode url #1317

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ RUN sudo apt-get update \
RUN sudo mkdir -p /docker-entrypoint-initaws.d
RUN sudo chown gitpod /docker-entrypoint-initaws.d

# Installs IBMPlexSans-Regular.ttf for QRCodeService.
RUN sudo wget https://github.com/IBM/plex/blob/master/IBM-Plex-Sans/fonts/complete/ttf/IBMPlexSans-Regular.ttf?raw=true -O /usr/share/fonts/truetype/IBMPlexSans-Regular.ttf
RUN sudo fc-cache -f

USER gitpod

ENV NODE_ENV=development
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ EXPOSE 3000

RUN apk update && apk add ttf-freefont && rm -rf /var/cache/apk/*

# Installs IBMPlexSans-Regular.ttf for QRCodeService.
RUN wget https://github.com/IBM/plex/blob/master/IBM-Plex-Sans/fonts/complete/ttf/IBMPlexSans-Regular.ttf?raw=true -O /usr/share/fonts/TTF/IBMPlexSans-Regular.ttf
RUN fc-cache -f

# Install libraries
COPY package.json package-lock.json ./

Expand Down
14 changes: 13 additions & 1 deletion src/server/modules/qr/services/QrCodeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ export class QrCodeService implements interfaces.QrCodeService {
.attr('height', `${imageHeight}`)
.attr('xmlns', 'http://www.w3.org/2000/svg')

// Sources IBM Plex Sans font from Google Fonts and defines the text style.
// This only affects QRCodes that are exported to SVGs.
// Note that sharp sources the font file from the Docker container that the
// instance is run on. Refer to Dockerfile for the installation.
svg.append(
`<defs>
<style type="text/css">
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&amp;display=swap");
</style>
</defs>`,
)

// Provides the entire graphic with a white background.
svg.append('<rect></rect>')
dom('rect')
Expand Down Expand Up @@ -114,7 +126,7 @@ export class QrCodeService implements interfaces.QrCodeService {
.attr('x', `${textLocationX}`)
.attr('y', `${textLocationY + i * FONT_SIZE * LINE_HEIGHT}`)
.attr('text-anchor', 'middle')
.attr('font-family', 'sans-serif')
.attr('font-family', 'IBM Plex Sans, sans-serif')
.attr('font-weight', '400')
.attr('font-size', `${FONT_SIZE}px`)
.text(line)
Expand Down