Git Product home page Git Product logo

Comments (12)

WordlessEcho avatar WordlessEcho commented on September 3, 2024

我好像看到了很多可能性,比如用FontManagerService直接修改fonts.xml
至于你说的无法更新fallback family和需要正确的postScriptName这两点我还没看出来

# cmd font help

Font service (font) commands
help
    Print this help text.

dump [family name]
    Dump all font files in the specified family name.
    Dump current system font configuration if no family name was specified.

update [font file path] [signature file path]
    Update installed font files with new font file.

update-family [family definition XML path]
    Update font families with the new definitions.

install-debug-cert [cert file path]
    Install debug certificate file. This command can be used only on userdebug
    or eng device with root user.

clear
    Remove all installed font files and reset to the initial state.

restart
    Restart FontManagerService emulating device reboot.
    WARNING: this is not a safe operation. Other processes may misbehave if
    they are using fonts updated by FontManagerService.
    This command exists merely for testing.

status
    Prints status of current system font configuration.
# cmd font dump sans-serif | egrep 'Hans|Hant|Jpan|Kore|CJK'

Family: langTag = zh-Hans-CN
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSansCJK-Regular.ttc, index = 2
Family: langTag = zh-Hant-TW,zh-Bopo-TW
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSansCJK-Regular.ttc, index = 3
Family: langTag = ja-Jpan-JP
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSansCJK-Regular.ttc
Family: langTag = ko-Kore-KR
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSansCJK-Regular.ttc, index = 1
# cmd font dump serif | egrep 'Hans|Hant|Jpan|Kore|CJK'

Family: langTag = zh-Hans-CN
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSerifCJK-Regular.ttc, index = 2
Family: langTag = zh-Hant-TW,zh-Bopo-TW
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSerifCJK-Regular.ttc, index = 3
Family: langTag = ja-Jpan-JP
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSerifCJK-Regular.ttc
Family: langTag = ko-Kore-KR
  FontStyle { weight=400, slant=0}, path = /system/fonts/NotoSerifCJK-Regular.ttc, index = 1

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

update-family的具体用法

/**
* Parses XML representing {@link android.graphics.fonts.FontFamilyUpdateRequest}.
*
* <p>The format is like:
* <pre>{@code
*   <fontFamilyUpdateRequest>
*       <family name="family-name">
*           <font name="postScriptName"/>
*       </family>
*   </fontFamilyUpdateRequest>
* }</pre>
*/

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/FontManagerShellCommand.java;l=449;drc=e9b53c20c8ab211d13a483a037021de310577ab2

/**
* Read a {@link Family} instance from &lt;family&gt; element in XML
*
* For the XML format, see {@link Font} class comment.
*
* @param parser an XML parser that points &lt;family&gt; element.
* @return an {@link Family} instance
*/

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/graphics/fonts/FontUpdateRequest.java;l=276;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

/**
* Font object used for update.
*
* Here is an example of Family/Font XML.
* <family name="my-sans">
*   <font name="MySans" weight="400" slant="0" axis="'wght' 400 'ital' 0" index="0" />
*   <font name="MySans" weight="400" slant="0" axis="'wght' 400 'ital' 1" index="0" />
*   <font name="MySans" weight="400" slant="0" axis="'wght' 700 'ital' 0" index="0" />
*   <font name="MySans" weight="400" slant="0" axis="'wght' 700 'ital' 1" index="0" />
* </family>
*
* @see Font#readFromXml(XmlPullParser)
* @see Font#writeToXml(TypedXmlSerializer, Font)
* @see Family#readFromXml(XmlPullParser)
* @see Family#writeFamilyToXml(TypedXmlSerializer, Family)
*/

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/graphics/fonts/FontUpdateRequest.java;l=71;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

看来读取postScriptName靠的是TTC index为0时,OpenType name table中的数据

fontFileName = mParser.buildFontFileName(tempNewFontFile);

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java;l=365;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

UpdatableFontDir(File filesDir, FontFileParser parser, FsverityUtil fsverityUtil,
        File configFile) {
    this(filesDir, parser, fsverityUtil, configFile,
            System::currentTimeMillis,
            (map) -> SystemFonts.getSystemFontConfig(map, 0, 0)
    );
}

// For unit testing
UpdatableFontDir(File filesDir, FontFileParser parser, FsverityUtil fsverityUtil,
        File configFile, Supplier<Long> currentTimeSupplier,
        Function<Map<String, File>, FontConfig> configSupplier) {
    mFilesDir = filesDir;
    mParser = parser;
    mFsverityUtil = fsverityUtil;
    mConfigFile = new AtomicFile(configFile);
    mCurrentTimeSupplier = currentTimeSupplier;
    mConfigSupplier = configSupplier;
}

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java;l=144;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

@Nullable
private UpdatableFontDir createUpdatableFontDir() {
    // Never read updatable font files in safe mode.
    if (mIsSafeMode) return null;
    // If apk verity is supported, fs-verity should be available.
    if (!VerityUtils.isFsVeritySupported()) return null;

    String[] certs = mContext.getResources().getStringArray(
            R.array.config_fontManagerServiceCerts);

    if (mDebugCertFilePath != null && (Build.IS_USERDEBUG || Build.IS_ENG)) {
        String[] tmp = new String[certs.length + 1];
        System.arraycopy(certs, 0, tmp, 0, certs.length);
        tmp[certs.length] = mDebugCertFilePath;
        certs = tmp;
    }

    return new UpdatableFontDir(new File(FONT_FILES_DIR), new OtfFontFileParser(),
            new FsverityUtilImpl(certs), new File(CONFIG_XML_FILE));
}

// ...

private void initialize() {
    synchronized (mUpdatableFontDirLock) {
        mUpdatableFontDir = createUpdatableFontDir();
        if (mUpdatableFontDir == null) {
            setSerializedFontMap(serializeSystemServerFontMap());
            return;
        }
        mUpdatableFontDir.loadFontFileMap();
        updateSerializedFontMap();
    }
}

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/FontManagerService.java;l=263;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

@Override
public String getPostScriptName(File file) throws IOException {
    ByteBuffer buffer = mmap(file);
    try {
        return FontFileUtil.getPostScriptName(buffer, 0);
    } finally {
        unmap(buffer);
    }
}

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/OtfFontFileParser.java;l=40;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

/**
* Analyze name OpenType table and return PostScript name.
*
* IllegalArgumentException will be thrown for invalid font data.
* null will be returned if not found or the PostScript name is invalid.
*
* @param buffer a buffer of OpenType font
* @param index a font index
* @return a post script name or null if it is invalid or not found.
*/

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/graphics/java/android/graphics/fonts/FontFileUtil.java;l=164;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

我知道为啥说fallback改不了了(((

// We should keep the first font family (config.getFontFamilies().get(0)) because it's used
// as a fallback font. See SystemFonts.java.

https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java;l=583;drc=b14b5b8d12bf7f7a6dbf25cb275e247440450fce

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

fontRevision是版本号吧?

<head>
  <!-- Most of this table will be recalculated by the compiler -->
  <tableVersion value="1.0"/>
  <fontRevision value="2.002"/>
  <!-- ... -->
</head>

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024
# cmd font dump sans-serif | grep Droid

  FontStyle { weight=400, slant=0}, path = /system/fonts/DroidSansFallback.ttf
  FontStyle { weight=400, slant=0}, path = /system/fonts/DroidSansFallbackFull.ttf

from notocjk.

dantmnf avatar dantmnf commented on September 3, 2024

fontRevision是版本号吧?

<head>
  <!-- Most of this table will be recalculated by the compiler -->
  <tableVersion value="1.0"/>
  <fontRevision value="2.002"/>
  <!-- ... -->
</head>

https://learn.microsoft.com/en-us/typography/opentype/spec/head

是一个定点数,而且整个文件有 checksum。

可能要写点 java 然后用 app_process 跑,顺便把现在那堆正则 xml 换掉(

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

好了,我研究完了,我现在的猜测是你想不再通过替换或新增任何文件的方式,修改字体?

目前我们替换和新增的文件有:

  • /system/etc/fonts.xml
  • /system_ext/etc/fonts.xml(一加氧OS/氢OS)
  • /system/fonts/DroidSansFallback.ttf
  • /system/fonts/DroidSansFallbackFull.ttf
  • /system/fonts/NotoSansCJK-Regular.ttc
  • /system/fonts/NotoSansCJK-VF.otf.ttc
  • /system/fonts/NotoSerifCJK-Regular.ttc
  • /system/fonts/NotoSerifCJK-VF.otf.ttc

如果想不修改任何文件,那是不可能的。至少fonts.xml要修改。然后字体如果你不想放到/system里,可以在fonts.xml里指定换个位置放

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

fontRevision是版本号吧?

<head>
  <!-- Most of this table will be recalculated by the compiler -->
  <tableVersion value="1.0"/>
  <fontRevision value="2.002"/>
  <!-- ... -->
</head>

https://learn.microsoft.com/en-us/typography/opentype/spec/head

是一个定点数,而且整个文件有 checksum。

可能要写点 java 然后用 app_process 跑,顺便把现在那堆正则 xml 换掉(

这个2.002的fontRevision是我用fonttool跑出来的,我很确定他是字体版本号

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

如果你想隐藏这个模块的话,是不是可以用Zygisk来做这个模块?可惜我完全不会Zygisk

from notocjk.

WordlessEcho avatar WordlessEcho commented on September 3, 2024

我重新思考了一下,你只是希望在/proc/self/maps里让文件的路径指向/data
我想的是用户可以装一个旧版的notocjk模块进去,然后写一个模块或脚本执行cmd font update XDDDDD

from notocjk.

dantmnf avatar dantmnf commented on September 3, 2024

我重新思考了一下,你只是希望在/proc/self/maps里让文件的路径指向/data

对,主要是要在 /data 里找个应用能访问的地方


不过我又想了一下,应用还是可以在 /system 下面随便找一堆文件 stat 拿设备号,感觉意义不是太大(

真要藏模块可能要上增量更新的同款 dm-snapshot 了

from notocjk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.