Skip to content

Commit

Permalink
add FreeSerif font to handle special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
dippindots committed Mar 22, 2019
1 parent 871b94c commit 0755104
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
25 changes: 11 additions & 14 deletions src/pages/studyView/charts/barChart/BarChartAxisLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,29 @@ export class BarChartAxisLabel extends VictoryLabel {
key: style[0].textAnchor || textAnchor
};

let tspan;
let tspan = [];

// add the second string as a superscript
// we are not using baselineShift property due to compatibility issues, instead adjusting dy
// for more details see https://stackoverflow.com/questions/12332448/subscripts-and-superscripts-in-svg
if (content.length > 1) {
tspan = (
<tspan {...tspanProps}>
{content[0]}
<tspan
dy={-style[0].fontSize/2}
style={{...style[0], fontSize: "70%"}}
>
{content[1]}
</tspan>
</tspan>
);
tspan.push(<tspan {...tspanProps}>{content[0]}</tspan>);
tspan.push(
<tspan
dy={-style[0].fontSize/2}
style={{...style[0], fontSize: style[0].fontSize * 0.7}}
>
{content[1]}
</tspan>);
}
else {
tspan = <tspan {...tspanProps}>{content[0]}</tspan>;
tspan.push(<tspan {...tspanProps}>{content[0]}</tspan>);
}

return React.cloneElement(
props.textComponent,
{ dx, dy, x, y, events, transform, className, title, desc },
[tspan]
tspan
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/shared/lib/svgToPdfDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export default function svgToPdfDownload(fileName: string, svg: any) {
}

const pdf = new jsPDF(direction, 'pt', [width, height]);


const font = require("shared/static-data/font.json");
pdf.addFileToVFS("FreeSans-normal.ttf", font.FreeSans);
pdf.addFont("FreeSans-normal.ttf", "FreeSans", "normal");

// render the svg element
svg2pdf(svg, pdf, {
xOffset: 0,
Expand Down
1 change: 1 addition & 0 deletions src/shared/static-data/font.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/shared/theme/cBioPoralTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const baseProps = {
// * Labels
// *
export const baseLabelStyles = {
fontFamily: sansSerif,
fontFamily: `FreeSans, ${sansSerif}`,
fontSize,
letterSpacing,
padding,
Expand Down

0 comments on commit 0755104

Please sign in to comment.