จัดการธีมการนำเสนอบน Android
บทนำ
ธีมการนำเสนอกำหนดคุณสมบัติขององค์ประกอบการออกแบบ เมื่อคุณเลือกธีมการนำเสนอ คุณกำลังเลือกชุดขององค์ประกอบภาพและคุณสมบัติเฉพาะของมัน
ใน PowerPoint ธีมประกอบด้วยสี, ฟอนต์, สไตล์พื้นหลัง, และเอฟเฟ็กต์

เปลี่ยนสีธีม
ธีม PowerPoint ใช้ชุดสีเฉพาะสำหรับองค์ประกอบต่าง ๆ บนสไลด์ หากคุณไม่ชอบสีเหล่านั้น คุณสามารถเปลี่ยนสีโดยกำหนดสีใหม่ให้กับธีม เพื่อให้คุณเลือกสีธีมใหม่ Aspose.Slides ให้ค่าไว้ภายใต้การนับจำนวนของ enumeration SchemeColor
โค้ด Java นี้แสดงวิธีเปลี่ยนสีอักเซนท์สำหรับธีม:
Presentation pres = new Presentation();
try {
IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
} finally {
if (pres != null) pres.dispose();
}
คุณสามารถหาค่าที่แท้จริงของสีที่ได้จากการเปลี่ยนแปลงนี้ได้โดย:
IFillFormatEffectiveData fillEffective = shape.getFillFormat().getEffective();
Color effectiveColor = fillEffective.getSolidFillColor();
System.out.println(String.format("Color [A=%d, R=%d, G=%d, B=%d]",
effectiveColor.getAlpha(), effectiveColor.getRed(), effectiveColor.getGreen(), effectiveColor.getBlue()));
เพื่อสาธิตการเปลี่ยนสีเพิ่มเติม เราจะสร้างองค์ประกอบอีกหนึ่งอันและกำหนดสีอักเซนท์ (จากการดำเนินการแรก) ให้กับมัน แล้วจึงเปลี่ยนสีในธีม:
IAutoShape otherShape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 120, 100, 100);
otherShape.getFillFormat().setFillType(FillType.Solid);
otherShape.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
pres.getMasterTheme().getColorScheme().getAccent4().setColor(Color.RED);
สีใหม่จะถูกนำไปใช้โดยอัตโนมัติบนทั้งสององค์ประกอบ
กำหนดสีธีมจากพาเลตเพิ่มเติม
เมื่อคุณทำการแปลงความสว่างของสีธีมหลัก (1) สีจากพาเลตเพิ่มเติม (2) จะถูกสร้างขึ้น จากนั้นคุณจึงสามารถตั้งค่าและรับค่าสีธีมเหล่านั้นได้

1 - สีธีมหลัก
2 - สีจากพาเลตเพิ่มเติม
โค้ด Java นี้แสดงการดำเนินการที่รับสีจากพาเลตเพิ่มเติมจากสีธีมหลักและนำไปใช้ในรูปทรง:
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
// Accent 4
IShape shape1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 50, 50);
shape1.getFillFormat().setFillType(FillType.Solid);
shape1.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
// Accent 4, สว่างขึ้น 80%
IShape shape2 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 70, 50, 50);
shape2.getFillFormat().setFillType(FillType.Solid);
shape2.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
shape2.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.MultiplyLuminance, 0.2f);
shape2.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.AddLuminance, 0.8f);
// Accent 4, สว่างขึ้น 60%
IShape shape3 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 130, 50, 50);
shape3.getFillFormat().setFillType(FillType.Solid);
shape3.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
shape3.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.MultiplyLuminance, 0.4f);
shape3.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.AddLuminance, 0.6f);
// Accent 4, สว่างขึ้น 40%
IShape shape4 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 190, 50, 50);
shape4.getFillFormat().setFillType(FillType.Solid);
shape4.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
shape4.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.MultiplyLuminance, 0.6f);
shape4.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.AddLuminance, 0.4f);
// Accent 4, สีเข้มขึ้น 25%
IShape shape5 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 250, 50, 50);
shape5.getFillFormat().setFillType(FillType.Solid);
shape5.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
shape5.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.MultiplyLuminance, 0.75f);
// Accent 4, สีเข้มขึ้น 50%
IShape shape6 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 310, 50, 50);
shape6.getFillFormat().setFillType(FillType.Solid);
shape6.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
shape6.getFillFormat().getSolidFillColor().getColorTransform().add(ColorTransformOperation.MultiplyLuminance, 0.5f);
presentation.save(path + "example_accent4.pptx", SaveFormat.Pptx);
} finally {
if (presentation != null) presentation.dispose();
}
แมป SchemeColor ไปยังสี IColorScheme
เมื่อคุณทำงานกับ SchemeColor คุณอาจสังเกตว่าในนั้นมีค่าธีมสีต่อไปนี้:
Background1, Background2, Text1, และ Text2
อย่างไรก็ตาม Presentation.getMasterTheme().getColorScheme() จะคืนค่า IColorScheme ซึ่งเปิดเผยสีที่สอดคล้องกันเป็น:
Dark1, Dark2, Light1, และ Light2
ความแตกต่างนี้อยู่ที่ชื่อเท่านั้น ค่าต่าง ๆ นี้อ้างอิงถึงสล็อตสีธีมเดียวกันและการแมปถูกกำหนดไว้คงที่:
Text1=Dark1Background1=Light1Text2=Dark2Background2=Light2
ไม่มีการแปลงแบบไดนามิกระหว่าง Text/Background และ Dark/Light พวกมันเป็นเพียงชื่อทางเลือกของสีธีมเดียวกัน
ความแตกต่างของชื่อมาจากศัพท์ของ Microsoft Office รุ่นเก่าจะใช้ Dark 1, Light 1, Dark 2, และ Light 2 ส่วน UI รุ่นใหม่จะแสดงสล็อตเดียวกันเป็น Text 1, Background 1, Text 2, และ Background 2
เปลี่ยนฟอนต์ธีม
เพื่อให้คุณสามารถเลือกฟอนต์สำหรับธีมและวัตถุประสงค์อื่น ๆ Aspose.Slides ใช้ตัวระบุพิเศษเหล่านี้ (คล้ายกับที่ใช้ใน PowerPoint):
- +mn-lt - ฟอนต์ข้อความหลัก Latin (Minor Latin Font)
- +mj-lt - ฟอนต์หัวเรื่อง Latin (Major Latin Font)
- +mn-ea - ฟอนต์ข้อความหลัก East Asian (Minor East Asian Font)
- +mj-ea - ฟอนต์หัวเรื่อง East Asian (Major East Asian Font)
โค้ด Java นี้แสดงวิธีกำหนดฟอนต์ Latin ให้กับองค์ประกอบธีม:
IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
Paragraph paragraph = new Paragraph();
Portion portion = new Portion("Theme text format");
paragraph.getPortions().add(portion);
shape.getTextFrame().getParagraphs().add(paragraph);
portion.getPortionFormat().setLatinFont(new FontData("+mn-lt"));
โค้ด Java นี้แสดงวิธีเปลี่ยนฟอนต์ธีมการนำเสนอ:
pres.getMasterTheme().getFontScheme().getMinor().setLatinFont(new FontData("Arial"));
ฟอนต์ในกล่องข้อความทั้งหมดจะถูกอัปเดต
TIP
คุณอาจต้องการดู ฟอนต์ PowerPointเปลี่ยนสไตล์พื้นหลังธีม
โดยค่าเริ่มต้น แอป PowerPoint ให้พื้นหลังที่กำหนดล่วงหน้า 12 รูป แต่เพียง 3 รูปจาก 12 รูปนี้จะถูกบันทึกในงานนำเสนอทั่วไป

ตัวอย่างเช่น หลังจากคุณบันทึกงานนำเสนอในแอป PowerPoint คุณสามารถรันโค้ด Java นี้เพื่อค้นหาจำนวนพื้นหลังที่กำหนดล่วงหน้าในงานนำเสนอ:
Presentation pres = new Presentation("pres.pptx");
try {
int numberOfBackgroundFills = pres.getMasterTheme().getFormatScheme().getBackgroundFillStyles().size();
System.out.println("Number of background fill styles for theme is " + numberOfBackgroundFills);
} finally {
if (pres != null) pres.dispose();
}
โค้ด Java นี้แสดงวิธีตั้งค่าพื้นหลังสำหรับงานนำเสนอ:
pres.getMasters().get_Item(0).getBackground().setStyleIndex(2);
คู่มือดัชนี: 0 ใช้สำหรับไม่มีการเติม สี ดัชนีเริ่มจาก 1
TIP
คุณอาจต้องการดู พื้นหลัง PowerPointเปลี่ยนเอฟเฟ็กต์ธีม
ธีม PowerPoint ปกติมีค่าต่าง ๆ 3 ค่า สำหรับแต่ละอาร์เรย์สไตล์ ค่าพวกนี้ถูกรวมเป็น 3 เอฟเฟ็กต์: ละมุน (subtle), กลาง (moderate) และเข้ม (intense) ตัวอย่างเช่น นี่คือผลลัพธ์เมื่อเอฟเฟ็กต์เหล่านั้นถูกนำไปใช้กับรูปทรงเฉพาะ:

โดยใช้ 3 คุณสมบัติ (FillStyles, LineStyles, EffectStyles) จากคลาส FormatScheme คุณสามารถเปลี่ยนองค์ประกอบในธีม (ยืดหยุ่นกว่าตัวเลือกใน PowerPoint)
โค้ด Java นี้แสดงวิธีเปลี่ยนเอฟเฟ็กต์ธีมโดยการปรับส่วนต่าง ๆ ขององค์ประกอบ:
Presentation pres = new Presentation("Subtle_Moderate_Intense.pptx");
try {
pres.getMasterTheme().getFormatScheme().getLineStyles().get_Item(0).getFillFormat().getSolidFillColor().setColor(Color.RED);
pres.getMasterTheme().getFormatScheme().getFillStyles().get_Item(2).setFillType(FillType.Solid);
pres.getMasterTheme().getFormatScheme().getFillStyles().get_Item(2).getSolidFillColor().setColor(Color.GREEN);
pres.getMasterTheme().getFormatScheme().getEffectStyles().get_Item(2).getEffectFormat().getOuterShadowEffect().setDistance(10f);
pres.save("Design_04_Subtle_Moderate_Intense-out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
การเปลี่ยนแปลงที่เกิดขึ้นในสีเติม, ประเภทการเติม, เงา ฯลฯ:

คำถามที่พบบ่อย
ฉันสามารถใช้ธีมกับสไลด์เดียวโดยไม่ต้องเปลี่ยน Master ได้หรือไม่?
ได้ Aspose.Slides รองรับการแทนที่ธีมในระดับสไลด์ ดังนั้นคุณสามารถใช้ธีมเฉพาะท้องถิ่นกับสไลด์นั้นได้โดยที่ยังคงธีม Master อยู่ (ผ่าน SlideThemeManager)
วิธีที่ปลอดภัยที่สุดในการย้ายธีมจากงานนำเสนอหนึ่งไปยังอีกงานหนึ่งคืออะไร?
คัดลอกสไลด์ พร้อมกับ Master ของมันไปยังงานนำเป้าหมาย วิธีนี้จะคง Master, Layouts และธีมที่เกี่ยวข้องไว้ ทำให้รูปลักษณ์สอดคล้องกัน
ฉันจะดูค่าที่ “effective” หลังจากการสืบทอดและการแทนที่ทั้งหมดได้อย่างไร?
ใช้ “effective” view ของ API [/slides/th/androidjava/shape-effective-properties/] สำหรับธีม/สี/ฟอนต์/เอฟเฟ็กต์ วิธีนี้จะคืนค่าคุณสมบัติที่ได้รับการแก้ไขขั้นสุดท้ายหลังจากนำ Master และการแทนที่ท้องถิ่นมาประยุกต์ใช้.