Method: FPDF#SetFont

Defined in:
lib/fpdf.rb

#SetFont(family, style = '', size = 0) ⇒ Object



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/fpdf.rb', line 479

def SetFont(family, style='', size=0)
    # Select a font; size given in points
    family.downcase!
    family=@FontFamily if family==''
    if family=='arial'
        family='helvetica'
    elsif family=='symbol' or family=='zapfdingbats'
        style=''
    end
    style.upcase!
    unless style.index('U').nil?
        @underline=true
        style.gsub!('U','')
    else
        @underline=false;
    end
    style='BI' if style=='IB'
    size=@FontSizePt if size==0
    # Test if font is already selected
    return if @FontFamily==family and
        @FontStyle==style and @FontSizePt==size
    # Test if used for the first time
    fontkey=family+style
    unless @fonts.has_key?(fontkey)
        if @CoreFonts.has_key?(fontkey)
            unless Charwidths.has_key?(fontkey)
                raise 'Font unavailable'
            end
            @fonts[fontkey]={
                'i'=>@fonts.size,
                'type'=>'core',
                'name'=>@CoreFonts[fontkey],
                'up'=>-100,
                'ut'=>50,
                'cw'=>Charwidths[fontkey]}
        else
            raise 'Font unavailable'
        end
    end

    #Select it
    @FontFamily=family
    @FontStyle=style;
    @FontSizePt=size
    @FontSize=size/@k;
    @CurrentFont=@fonts[fontkey]
    if @page>0
        out(sprintf('BT /F%d %.2f Tf ET', @CurrentFont['i'], @FontSizePt))
    end
end