Module: Asposeslidesjava::TextFont

Defined in:
lib/asposeslidesjava/Text/textfont.rb

Instance Method Summary collapse

Instance Method Details

#font_family_of_textObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/asposeslidesjava/Text/textfont.rb', line 64

def font_family_of_text()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class

    pres = Rjb::import('com.aspose.slides.Presentation').new

    # Get the first slide

    sld = pres.getSlides().get_Item(0)

    # Add an AutoShape of Rectangle type

    ashp = sld.getShapes().addAutoShape(Rjb::import('com.aspose.slides.ShapeType').Rectangle, 50, 50, 200, 50)

    # Remove any fill style associated with the AutoShape

    ashp.getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').NoFill)

    # Access the TextFrame associated with the AutoShape

    tf = ashp.getTextFrame()
    tf.setText("Aspose TextBox")

    # Access the Portion associated with the TextFrame

    port = tf.getParagraphs().get_Item(0).getPortions().get_Item(0)

    # Set the Font for the Portion

    port.getPortionFormat().setLatinFont(Rjb::import('com.aspose.slides.FontData').new("Times New Roman"))

    # Set Bold property of the Font

    port.getPortionFormat().setFontBold(Rjb::import('com.aspose.slides.NullableBool').True)

    # Set Italic property of the Font

    port.getPortionFormat().setFontItalic(Rjb::import('com.aspose.slides.NullableBool').True)

    # Set Underline property of the Font

    port.getPortionFormat().setFontUnderline(Rjb::import('com.aspose.slides.TextUnderlineType').Single)

    # Set the Height of the Font

    port.getPortionFormat().setFontHeight(25)

    # Set the color of the Font

    port.getPortionFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)
    port.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Rjb::import('java.awt.Color').BLUE)

    # Write the presentation as a PPTX file 

    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "FontFamilyOfText.pptx", save_format.Pptx)

    puts "Done with font family for text, please check the output file."
end

#font_propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/asposeslidesjava/Text/textfont.rb', line 14

def font_properties()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class

    pres = Rjb::import('com.aspose.slides.Presentation').new(data_dir + 'Welcome.pptx')

    # Get the first slide

    slide = pres.getSlides().get_Item(0)

    # Accessing the first and second placeholder in the slide and typecasting it as AutoShape

    tf1 = slide.getShapes().get_Item(0).getTextFrame()
    tf2 = slide.getShapes().get_Item(1).getTextFrame()

    # Accessing the first Paragraph

    para1 = tf1.getParagraphs().get_Item(0)
    para2 = tf2.getParagraphs().get_Item(0)

    # Accessing the first portion

    port1 = para1.getPortions().get_Item(0)
    port2 = para2.getPortions().get_Item(0)

    # Define new fonts

    fd1 = Rjb::import('com.aspose.slides.FontData').new("Elephant")
    fd2 = Rjb::import('com.aspose.slides.FontData').new("Castellar")

    # Assign new fonts to portion

    port1.getPortionFormat().setLatinFont(fd1)
    port2.getPortionFormat().setLatinFont(fd2)

    # Set font to Bold

    port1.getPortionFormat().setFontBold(Rjb::import('com.aspose.slides.NullableBool').True)
    port2.getPortionFormat().setFontBold(Rjb::import('com.aspose.slides.NullableBool').True)

    # Set font to Italic

    port1.getPortionFormat().setFontItalic(Rjb::import('com.aspose.slides.NullableBool').True)
    port2.getPortionFormat().setFontItalic(Rjb::import('com.aspose.slides.NullableBool').True)

    # Set font color

    port1.getPortionFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)
    port1.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Rjb::import('java.awt.Color').BLUE)
    port2.getPortionFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)
    port2.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Rjb::import('java.awt.Color').GREEN)

    # Write the presentation as a PPTX file 

    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "WelcomeFont.pptx", save_format.Pptx)

    puts "Done with font properties, please check the output file."
end

#initializeObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/asposeslidesjava/Text/textfont.rb', line 3

def initialize()
    # Managing Font Related Properties

    font_properties()

    # Managing Font Family of Text

    font_family_of_text()

    # Using Default Fonts for Rendering Presentation

    set_default_font_for_rendering()
end

#set_default_font_for_renderingObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/asposeslidesjava/Text/textfont.rb', line 112

def set_default_font_for_rendering()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Use load options to define the default regualr and asian fonts                               

    lo = Rjb::import('com.aspose.slides.LoadOptions').new(Rjb::import('com.aspose.slides.LoadFormat').Auto)                                           
    lo.setDefaultRegularFont("Wingdings")                                                         
    lo.setDefaultAsianFont("Wingdings") 

    # Create an instance of Presentation class

    pres = Rjb::import('com.aspose.slides.Presentation').new(data_dir + 'input.pptx')
                                                                                            
    # Generate PDF 

    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "output.pdf", save_format.Pdf)

    puts "Done with font family for text, please check the output file."
end