| @@ -63,10 +63,18 @@ | ||
| 63 | 63 | ] |
| 64 | 64 | ]; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public static function get_css( $attribute_value, $property = '', $device = '', $attribute_global_name = '' ) { | |
| 68 | - global $ablocks_fonts; | |
| 67 | + /** | |
| 68 | + * @param mixed $attribute_value Stored typography object. | |
| 69 | + * @param string $property Unused legacy argument. | |
| 70 | + * @param string $device Device suffix. | |
| 71 | + * @param string $attribute_global_name Global typography id, if any. | |
| 72 | + * @param bool $expand_font_stack Whether to turn the stored family into | |
| 73 | + * a full stack. The atomic compiler must | |
| 74 | + * pass false — see below. | |
| 75 | + */ | |
| 76 | + public static function get_css( $attribute_value, $property = '', $device = '', $attribute_global_name = '', $expand_font_stack = true ) { | |
| 69 | 77 | $global_value = []; |
| 70 | 78 | if ( $attribute_global_name ) { |
| 71 | 79 | $global_typography = wp_list_pluck( \Ablocks\Helper::get_settings( 'global_typography', [] ), 'value', 'id' ); |
| 72 | 80 | $global_value = ( isset( $global_typography[ $attribute_global_name ] ) ? (array) $global_typography[ $attribute_global_name ] : [] ); |
| @@ -88,24 +96,36 @@ | ||
| 88 | 96 | $css[ $prop ] = $local_unit ? $local_val . $local_unit : $local_val; |
| 89 | 97 | } |
| 90 | 98 | }; |
| 91 | 99 | |
| 92 | - // Font family (special: also track font weights for enqueue) | |
| 100 | + // Font family. Output the CSS value only — font *discovery* is no longer | |
| 101 | + // done at render time. The set of fonts a page uses is collected from | |
| 102 | + // saved block attributes (FontCollector) and emitted by core via | |
| 103 | + // theme.json (CoreFontRegistry). See docs/FONT-MANAGEMENT-PLAN.md. | |
| 104 | + // | |
| 105 | + // The stored attribute is a bare family name (that name doubles as the | |
| 106 | + // download key), so FontStack turns it into a real stack — quoted, with a | |
| 107 | + // metric-adjusted fallback face and a generic tail derived from the font's | |
| 108 | + // own category. There is no per-block fallback field: `fontFallback` is | |
| 109 | + // read only so a value set through a filter still wins. | |
| 93 | 110 | if ( ! empty( $global_value['fontFamily'] ) ) { |
| 94 | 111 | $css['font-family'] = "var(--ablocks-{$attribute_global_name}-font-family)"; |
| 95 | 112 | } elseif ( ! empty( $value['fontFamily'] ) ) { |
| 96 | - $font_family = $value['fontFamily']; | |
| 97 | - $font_weight = ! empty( $value['weight'] ) ? $value['weight'] : '400'; | |
| 98 | - $css['font-family'] = $font_family; | |
| 99 | - | |
| 100 | - if ( isset( $ablocks_fonts[ $font_family ] ) ) { | |
| 101 | - if ( ! in_array( $font_weight, $ablocks_fonts[ $font_family ], true ) ) { | |
| 102 | - $ablocks_fonts[ $font_family ][] = $font_weight; | |
| 103 | - } | |
| 104 | - } else { | |
| 105 | - $ablocks_fonts[ $font_family ] = [ $font_weight ]; | |
| 113 | + // A stored family becomes a full stack everywhere EXCEPT the atomic | |
| 114 | + // compiler, whose declarations are hashed in JS at save time and | |
| 115 | + // again here at render time and must agree byte for byte. A stack | |
| 116 | + // cannot take part in that: it depends on the metrics table, the | |
| 117 | + // `font_metric_fallback` setting and the `ablocks/font_stack` | |
| 118 | + // filter, none of which the editor can see. | |
| 119 | + $family = $expand_font_stack | |
| 120 | + ? \ABlocks\Classes\FontStack::build( | |
| 121 | + $value['fontFamily'], | |
| 122 | + isset( $value['fontFallback'] ) ? $value['fontFallback'] : '' | |
| 123 | + ) | |
| 124 | + : $value['fontFamily']; | |
| 125 | + if ( '' !== $family ) { | |
| 126 | + $css['font-family'] = $family; | |
| 106 | 127 | } |
| 107 | - update_option( ABLOCKS_FONTS_SETTINGS_NAME, wp_json_encode( $ablocks_fonts ) ); | |
| 108 | 128 | } |
| 109 | 129 | |
| 110 | 130 | // Desktop-only styles |
| 111 | 131 | if ( empty( $device ) ) { |
| @@ -130,8 +150,32 @@ | ||
| 130 | 150 | |
| 131 | 151 | $css_var_name = $css_prop . ( $device ? '-' . strtolower( $device ) : '' ); |
| 132 | 152 | |
| 133 | 153 | $add_prop( $css_prop, $local_val, $local_unit, $global_key, $css_var_name ); |
| 154 | + } | |
| 155 | + | |
| 156 | + /* | |
| 157 | + * Columns, direction and text stroke. Appended after the original | |
| 158 | + * members so anything saved before these existed compiles byte-for-byte | |
| 159 | + * as it did — for atomic blocks the style class is a hash of this | |
| 160 | + * output. Desktop-only, like weight/transform/style/decoration above, | |
| 161 | + * and with no global-typography equivalent to fall back to. Mirrors the | |
| 162 | + * tail of typographyPairs() in src/blocks/atomic-shared/styles.js. | |
| 163 | + */ | |
| 164 | + if ( empty( $device ) ) { | |
| 165 | + if ( isset( $value['columns'] ) && '' !== $value['columns'] ) { | |
| 166 | + $css['column-count'] = $value['columns']; | |
| 167 | + } | |
| 168 | + if ( ! empty( $value['direction'] ) ) { | |
| 169 | + $css['direction'] = $value['direction']; | |
| 170 | + } | |
| 171 | + if ( isset( $value['strokeWidth'] ) && '' !== $value['strokeWidth'] ) { | |
| 172 | + $stroke_unit = ! empty( $value['strokeWidthUnit'] ) ? $value['strokeWidthUnit'] : 'px'; | |
| 173 | + $css['-webkit-text-stroke-width'] = $value['strokeWidth'] . $stroke_unit; | |
| 174 | + } | |
| 175 | + if ( ! empty( $value['strokeColor'] ) ) { | |
| 176 | + $css['-webkit-text-stroke-color'] = $value['strokeColor']; | |
| 177 | + } | |
| 134 | 178 | } |
| 135 | 179 | |
| 136 | 180 | return $css; |
| 137 | 181 | } |