So if trust income is a mixture of dividend, capital gain and tax-free income (from muni bonds or principal), the ordinary income must be used up before the payout can be taxed as gain, and gain must be used before the payout can be tax-free.
FORBES: The new giving game