A Framework for Quantifying How Pre-Training and Context Benefit In-Context Learning