java - iText Font Strategy -


i have web application generate pdf data , allow user download. have custom font registering 4 font files (regular, bold, italic, , bold italic ttf files).

  1. is necessary? can use regular font file , set weight/styles through font class or need files? looks works ok still learning.

  2. what strategy or pattern managing these different fonts put documents? has done java perspective?

you're not telling how you're registering fonts, nor how you're using them, let me tell how work (i'm original developer of itext). if you're using 4 fonts, best way register them this:

basefont bfregular = basefont.createfont(regularttf, basefont.identity_h, basefont_embedded); basefont bfbold = basefont.createfont(boldttf, basefont.identity_h, basefont_embedded); basefont bfitalic = basefont.createfont(italicttf, basefont.identity_h, basefont_embedded); basefont bfbolditalic = basefont.createfont(bolditalicttf, basefont.identity_h, basefont_embedded); 

i'd use these basefont instances whenever adding content using low-level operations.

then do:

font fregular = new font(bfregular, 12); font fbold = new font(bfbold, 12); font fitalic = new font(bfitalic, 12); font fbolditalic = new font(bfbolditalic, 12); 

i'd use these fonts whenever need create high-level object, such paragraph.

of course, may need this:

font fregularsmall = new font(bfregular, 9); font fboldsmall = new font(bfbold, 9); font fitalicsmall = new font(bfitalic, 9); font fbolditalicsmall = new font(bfbolditalic, 9); font fregularbig = new font(bfregular, 20); font fboldbig = new font(bfbold, 20); font fitalicbig = new font(bfitalic, 20); font fbolditalicbig = new font(bfbolditalic, 20); 

usually, create helper class in create basefont objects once (they need reused), , create getters font objects.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -