Substitution / Suche von Fonts

Fonts für Annotationen werden anhand von AnnotationFontFactory-Implementationen für die Darstellung / das Rendering zur Verfügung gestellt. AnnotationFontFactory-Implementationen können im Annotationsprofil definiert und einem bestimmten Annotationstyp zugeordnet oder zentral in der Annotations-Klasse via setDefaultAnnotationFontFactory-Methode registriert werden. Definitionen im Annotationsprofil haben immer Vorrang. Wenn keine Definition vorhanden ist, wird auf die Annotations-Klasse zurückgegriffen. Es muss letztendlich immer eine AnnotationFontFactory-Implementation mit einer Fallback-FontSource wie Beispielsweise AnnotationBasicFontFactory oder SwingAnnotationBasicFontFactory definiert werden. Kann der Font nicht bestimmt werden, werden Fehler im Programmcode ausgelöst, der Anzeigevorgang wird nicht korrekt ausgeführt und die weitere Verarbeitung wird unterbrochen.

Definitionsmöglichkeiten von AnnotationFontFactory-Implementationen:

  • Annotationstyp spezifische Definition im Annotationsprofil (Klasse muss einen Standardkonstruktor besitzen):

    <annotation-type name="BaseText" archetype="BaseText" class="com.levigo.jadice.annotation.TextAnnotation">
        ...
        <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileLogicalFontFactory"/>
        <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileStandard14FontFactory"/>
        <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileSystemFontFactory"/>
        <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileBasicFontFactory"/>
        ...
    </annotation-type>
    
                        

    Die AnnotationFontFactory-Implementationen können auch in einer ChainedAnnotationFontFactory-Implementation zusammengefasst (siehe Beispiel weiter unten) und mit nur einem Eintrag definiert werden. Änderungen (zum Beispiel Reihenfolge anpassen oder Deaktivieren von Definitionen) müssen dann jedoch im Quelltext vorgenommen werden.

  • Registrierung in der Annotations-Klasse:

    FontManagerFuture fontManagerFuture = ...                        
    Annotations.setDefaultAnnotationFontFactory(
        new SwingAnnotationStandard14FontFactory(fontManagerFuture));
    
                        

AnnotationFontFactory-Implementationen können auch mit Hilfe der ChainedAnnotationFontFactory-Klasse verkettet / zusammengefasst werden, siehe auch Beispiel 7.15, „Verwendung der ChainedFontFactory. Die AnnotationFontFactory-Implementationen werden in definierter Reihenfolge abgefragt. Bei einer erfolgreichen Suche wird die gefundene Font-Instanz zurückgegeben und der Abfragevorgang wird beendet. Wird nichts gefunden wird null zurückgegeben.

  • Registrierung in der Annotations-Klasse via ChainedAnnotationFontFactory-Klasse:

    FontManagerFuture fontManagerFuture = ...                        
    Annotations.setDefaultAnnotationFontFactory(//
        new ChainedSwingAnnotationFontFactory(//
            new SwingAnnotationLogicalFontFactory(fontManagerFuture), //
            new SwingAnnotationStandard14FontFactory(fontManagerFuture), //
            new SwingAnnotationSystemFontFactory(fontManagerFuture) //
        )//
    );
    
                        
[jadice document platform Version 5.6.10.6: Dokumentation für Entwickler. Veröffentlicht: 2024-01-18]