mapbox / mapbox/mapbox-maps-ios

Local font Chinese does not take effect

Open
#2,162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Xcode version: 15.2
  • iOS version: 17.2
  • Devices affected: iphone1 5 pro max
  • Maps SDK Version: 11.1.0

hello,I used the following code to set local fonts for mapbox,but only letters and numbers are valid, Chinese characters are not valid.

code:

let center = CLLocationCoordinate2D(latitude: 40.669957, longitude: -103.5917968)
        let cameraOptions = CameraOptions(center: center, zoom: 2)
        if let path = Bundle.main.path(forResource: "blueprint_style", ofType: "json"),
           let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe),
           var json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
            let fontPath = "asset:/\(NSHomeDirectory())/Fonts/{fontstack}/{range}.pbf"
            json["glyphs"] = fontPath
            let styleJson = json.jsonString()
            
            let mapOptions = MapOptions(glyphsRasterizationOptions: GlyphsRasterizationOptions(rasterizationMode: .ideographsRasterizedLocally))
            let mapInitOptions = MapInitOptions(mapOptions: mapOptions, cameraOptions: cameraOptions, styleJSON: styleJson)

            mapView = MapView(frame: view.bounds, mapInitOptions: mapInitOptions)
            mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            mapView.tintColor = .lightGray

            view.addSubview(mapView)

            mapView.mapboxMap.onStyleLoaded.observeNext { [weak self] _ in
                self?.addPointClusters()
            }.store(in: &cancelables)
        }

The effect is as shown below
Simulator Screenshot - iPhone 15 Pro Max - 2024-04-12 at 13 53 08

The local fonts are as follows
Font.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior from the Swift snippet using the provided local font archive, Mapbox Maps SDK 11.1.0, and the stated iOS environment. Compare Chinese glyph rendering with letters and numbers, then trace the local glyph configuration and rasterization options. Done means Chinese characters render correctly from the local fonts, or the limitation and required configuration are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.