Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adaptive fonts synthesis option #123

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ de.cau.cs.kieler.sccharts.ui.synthesis.hooks.InducedDataflowHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ShowStateDependencyHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ActionsAsDataflowHook
de.cau.cs.kieler.sccharts.ui.debug.hooks.SetBreakpointActionHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ModelOrderHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ModelOrderHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.FontSizeHook
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright ${year} by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This code is provided under the terms of the Eclipse Public License (EPL).
*/
package de.cau.cs.kieler.sccharts.ui.synthesis.hooks

import com.google.inject.Inject
import de.cau.cs.kieler.klighd.SynthesisOption
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.krendering.KRendering
import de.cau.cs.kieler.klighd.krendering.KText
import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared
import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions
import de.cau.cs.kieler.sccharts.State
import de.cau.cs.kieler.sccharts.extensions.SCChartsControlflowRegionExtensions
import de.cau.cs.kieler.sccharts.extensions.SCChartsDataflowRegionExtensions
import de.cau.cs.kieler.sccharts.extensions.SCChartsScopeExtensions
import de.cau.cs.kieler.sccharts.extensions.SCChartsStateExtensions
import de.cau.cs.kieler.sccharts.ui.synthesis.GeneralSynthesisOptions

/**
* @author mka
*
*/
@ViewSynthesisShared
class FontSizeHook extends SynthesisHook {

@Inject extension SCChartsControlflowRegionExtensions
@Inject extension SCChartsDataflowRegionExtensions
@Inject extension SCChartsScopeExtensions
@Inject extension SCChartsStateExtensions
@Inject extension KRenderingExtensions

/** Action ID */
public static final String ID = "de.cau.cs.kieler.sccharts.ui.synthesis.hooks.FontSizeHook";

public static final SynthesisOption ADAPTIVE_FONTS =
SynthesisOption.createCheckOption("Adaptive Fonts", false)
.setCategory(GeneralSynthesisOptions::NAVIGATION)

static final int SIMPLE_STATE_FONT_SIZE = 11

static final double SIMPLE_STATE_INCREASE_FACTOR = 0.5

static final int MACRO_STATE_FONT_SIZE = 11

static final double MACRO_STATE_INCREASE_FACTOR = 1.0

static final int MAX_FONT_INCREASE = 15


/** Checks if given state should be visualized as macro state */
def boolean isMacroState(State state) {
return state.controlflowRegionsContainStates || state.containsDataflowRegions || !state.actions.empty ||
!state.declarations.empty || state.isReferencing || state.hasBaseStates;
}

/** returns a new font size based on the base size and the number of siblings
* crowded (many siblings) layouts get a larger font.
*/
def int dynamicFont(int baseSize, int siblingCount, double factor) {
return Math.min((baseSize + factor*(siblingCount - 1)).intValue(), (baseSize + factor*(MAX_FONT_INCREASE)).intValue())
}

override getDisplayedSynthesisOptions() {
return #[ADAPTIVE_FONTS]
}

override processState(State state, KNode node) {

if (ADAPTIVE_FONTS.booleanValue && state.parentRegion !== null) {

val macroFont = dynamicFont(MACRO_STATE_FONT_SIZE, state.parentRegion.states.size, MACRO_STATE_INCREASE_FACTOR)
val simpleFont = dynamicFont(SIMPLE_STATE_FONT_SIZE, state.parentRegion.states.size, SIMPLE_STATE_INCREASE_FACTOR)

if (state.isMacroState) {

node.data.filter(KRendering).map[it.eAllContents.toList].toList.flatten.forEach[
if (it instanceof KText) it.fontSize = macroFont
]
} else if (state.isSimple) {

node.eAllContents.filter(KRendering).toList.forEach[
if (it instanceof KText) it.fontSize = simpleFont
]
}
}
}
}
Loading