Skip to content

Commit

Permalink
font xml config #5
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Jan 10, 2024
1 parent d7965a3 commit 5e6b1cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- fj-doc-freemarker dependency
- xml font configuration

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler;

import com.lowagie.text.Document;
import com.lowagie.text.html.HtmlWriter;
import org.w3c.dom.Element;

public class HtmlTypeHandler extends DocTypeHandlerDefault {

Expand Down Expand Up @@ -40,4 +43,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
outputStream.close();
}

protected void handleConfigTag(Element config) throws ConfigException {
super.handleConfigTag(config);
OpenPDFConfigHelper.handleConfig( config, this.getType() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;
import org.w3c.dom.Element;

public class PdfTypeHandler extends DocTypeHandlerDefault {

Expand Down Expand Up @@ -59,4 +62,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
outputStream.close();
}

@Override
protected void handleConfigTag(Element config) throws ConfigException {
super.handleConfigTag(config);
OpenPDFConfigHelper.handleConfig( config, this.getType() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import org.fugerit.java.core.cfg.ConfigException;
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPDFConfigHelper;
import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.rtf.RtfWriter2;
import org.w3c.dom.Element;

public class RtfTypeHandler extends DocTypeHandlerDefault {

Expand Down Expand Up @@ -45,4 +48,9 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
outputStream.close();
}

protected void handleConfigTag(Element config) throws ConfigException {
super.handleConfigTag(config);
OpenPDFConfigHelper.handleConfig( config, this.getType() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
@Slf4j
public class OpenPDFConfigHelper {

public static final String TAG_NAME_FONT = "font";

public static final String ATT_NAME = "name";
public static final String ATT_PATH = "path";


public static void handleConfig( Element config, String type ) throws ConfigException {
log.info( "configure for type: {}", type );
NodeList fontList = config.getElementsByTagName( "font" );
NodeList fontList = config.getElementsByTagName( TAG_NAME_FONT );
for ( int k=0; k<fontList.getLength(); k++ ) {
Element currentFontTag = (Element) fontList.item( k );
String name = currentFontTag.getAttribute( "name" );
String path = currentFontTag.getAttribute( "path" );
String name = currentFontTag.getAttribute( ATT_NAME );
String path = currentFontTag.getAttribute( ATT_PATH );
log.info( "current font {} - {}", name, path );
ConfigException.apply( () -> OpenPpfDocHandler.registerFont( name , path ) );
}
Expand Down

0 comments on commit 5e6b1cc

Please sign in to comment.