글꼴 작업
글꼴은 특정 크기,색상 및 디자인의 문자 집합입니다. Aspose.Words는Font클래스를 포함하여 다양한 글꼴 관련 클래스를 사용하여 글꼴로 작업 할 수 있습니다.
글꼴 서식
현재 글꼴 서식은Font속성에 의해 반환되는Font개체로 표시됩니다. Font클래스에는Microsoft Word에서 가능한 다양한 글꼴 속성이 포함되어 있습니다.
다음 코드 예제에서는 글꼴 서식을 설정하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open the document. | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
// Specify font formatting before adding text. | |
Font font = builder.getFont(); | |
font.setSize(16); | |
font.setColor(Color.blue); | |
font.setBold(true); | |
font.setName("Arial"); | |
font.setUnderline(Underline.DASH); | |
builder.write("Sample text."); | |
doc.save(dataDir + "SetFontFormatting_out.doc"); |
채우기 속성은 이제 글꼴이 텍스트의 채우기 서식을 설정하는 데 사용할 수 있습니다. 예를 들어 텍스트 채우기의 전경색 또는 투명도를 변경할 수 있습니다.
글꼴 줄 간격 얻기
글꼴의 줄 간격은 두 개의 연속적인 텍스트 줄의 기준선 사이의 수직 거리입니다. 따라서 줄 간격에는 문자 자체의 높이와 함께 줄 사이의 빈 공간이 포함됩니다.
LineSpacing속성은 아래 예제와 같이 이 값을 얻기 위해Font클래스에 도입되었습니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetFontLineSpacing.class); | |
// Initialize document. | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
builder.getFont().setName("Calibri"); | |
builder.write("I'm a very nice formatted string."); | |
// Obtain line spacing. | |
Font font = builder.getDocument().getFirstSection().getBody().getFirstParagraph().getRuns().get(0).getFont(); | |
System.out.println("lineSpacing = " + font.getLineSpacing()); |
글꼴EmphasisMark
Font클래스는EmphasisMark속성을 제공하여 서식에 적용할EmphasisMark열거형 값을 가져오거나 설정합니다.
다음 코드 예제에서는EphasisMark속성을 설정하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document document = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(document); | |
builder.getFont().setEmphasisMark(EmphasisMark.UNDER_SOLID_CIRCLE); | |
builder.write("Emphasis text"); | |
builder.writeln(); | |
builder.getFont().clearFormatting(); | |
builder.write("Simple text"); | |
document.save(dataDir + "FontEmphasisMark_out.doc"); |